Why this matters
JavaScript shipped to production carries a surprising amount of dead weight. Single-line comments, verbose indentation, and blank lines between statements can account for 15 to 25 percent of a script's file size. On high-traffic sites, every kilobyte matters: it increases download time, slows parse-and-execute on mobile devices, and adds up across dozens of bundled scripts. A quick minification pass can shave meaningful latency off your page load without touching a build tool.
Full-featured minifiers like terser and esbuild are powerful, but they also perform aggressive transformations — variable mangling, dead-code elimination, and AST-level rewriting — that can introduce subtle bugs in complex or older codebases. This tool takes a conservative approach: it strips single-line `//` comments, blank lines, and leading whitespace while preserving block comments, string contents, and template literals verbatim. It is the right choice when you need size reduction without the risk of structural changes.
What gets removed and what stays
| Token type | Minify action | Beautify action |
|---|---|---|
| Single-line `//` comments | Removed | Removed (minified first) |
| Blank lines | Removed | Removed (minified first) |
| Leading whitespace | Collapsed | Re-indented by brace depth |
| Block `/* */` comments | Preserved | Preserved |
| String literals | Preserved verbatim | Preserved verbatim |
| Template literals | Preserved with newlines | Preserved with newlines |
| Variable names | Unchanged | Unchanged |
| ASI-sensitive newlines | Preserved | Preserved |
How to use it
Paste your JavaScript source code into the input panel.
Click Minify to strip single-line comments, blank lines, and leading whitespace while preserving all strings and block comments.
Check the byte savings indicator to see how much size you saved.
Click Beautify for simple re-indenting based on brace depth — useful for quick pretty-printing of minified code.
Copy the output with one click.
Testing your result
Run the minified output through a syntax checker or linter to confirm no valid code was accidentally broken. Paste both the original and minified versions into a diff tool and verify that only comments, whitespace, and blank lines were removed — every function name, variable, and string should be identical. If you have a test suite, run it against the minified code to catch any edge case where the tokenizer misidentified a comment boundary.
Common mistakes
Pasting code that contains regex literals with double slashes (like `/foo//bar/`), which the tokenizer may misread as a comment — this is a known limitation of the lightweight parser.
Expecting variable mangling or dead-code elimination, which this tool deliberately does not perform.
Using the beautifier as a replacement for Prettier — the simple brace-depth indenter handles basic formatting but lacks Prettier's opinionated style rules and plugin ecosystem.
Pasting code containing production secrets into any web-based tool, even though nothing is uploaded.
Edge cases and options
The tokenizer tracks single-quote, double-quote, and backtick delimiters with full escape-sequence awareness, so strings containing `//` or `/*` are never mistakenly treated as comments. Template literal newlines are also preserved. However, regex literals are not specially handled — if a regex contains `//`, the parser will incorrectly treat everything after the second slash as a comment. For production-grade minification of complex code, use esbuild or terser instead.
Real-world use cases
Developers quickly shrinking a script before embedding it in an HTML `onload` attribute or a bookmarklet where every byte counts.
Code reviewers beautifying minified vendor scripts to understand what a third-party library is actually doing.
Students comparing their verbose solutions against minified reference implementations in coding interviews.
Frequently asked questions
Q: Why is this called a conservative minifier?
A: It removes single-line comments, blank lines, and leading whitespace but does not touch block comments, strings, template literals, variable names, or ASI-sensitive newlines. No mangling or dead-code elimination is performed.
Q: Are strings and template literals preserved?
A: Yes. The tokenizer tracks quote types and escape sequences, copying strings verbatim. Template literal newlines are also preserved.
Q: Does it handle regex literals correctly?
A: Not specially — a regex like `/foo//bar/` would be misread because the `//` is treated as a comment start. For production code with complex regex, use a proper AST-based minifier.
Q: What does the Beautify mode do?
A: It first minifies the code, then re-formats it with one statement per line, indented by brace depth. It is a simple pretty-printer, not a full code formatter.
Q: Is this a replacement for terser or esbuild?
A: No. This tool is for quick, safe size reduction without structural changes. For production builds, use terser or esbuild, which perform AST-level optimizations including variable mangling and tree shaking.
Start using it now
Try the JS Minifier & Beautifier tool. See also CSS Minifier & Beautifier, JSON Formatter, and SQL Formatter.