JavaScript Minifier
Minify JavaScript by removing comments and collapsing whitespace. See compression statistics with original and minified size comparison.
What Whitespace Minification Catches and Misses
Paste JavaScript and the tool removes single-line // comments, multi-line /* */ comments, leading and trailing whitespace, newlines, and the spaces around operators and punctuation. A typical hand-written file shrinks 30-50% with this pass alone. The byte counter shows pre and post sizes, so you can see exactly what you saved. Combined with gzip on the server, the wire-transfer reduction is usually 70-80% versus raw source.
What this tool does NOT do is rename variables. A real production minifier like Terser or esbuild renames `customerOrderTotal` to `a`, mangles property names (when configured), removes dead code branches, and inlines small functions. Those passes need a full AST and a deep understanding of the language; they typically halve the file size again on top of whitespace stripping. For a one-off script, a snippet, or a small embedded widget, whitespace minification is fast and predictable. For shipping a 200KB SPA, use a bundler.
When Minification Goes Wrong
Naive whitespace minification can break JavaScript in subtle ways. Automatic semicolon insertion (ASI) is the worst offender: 'return\n{a:1}' is treated by the parser as 'return; {a:1};' and silently returns undefined. Stripping the newline doesn't change behaviour, but if your source relied on ASI to terminate a statement, joining lines with a missing semicolon can fuse two statements into one and change meaning entirely.
Template literals are another minefield. Whitespace inside `` `multi\n line` `` is significant; the tool preserves content inside backticks. Regex literals like /\s+/g must not be split or have their flags stripped. The minifier here is conservative and preserves all string and template content, so the result runs identically to the source on every JavaScript engine from V8 to Hermes. Run your test suite against the minified output before shipping; if you don't have tests, paste a sample, run it in the browser console, and verify the result matches.
Minification Approaches Compared
| Technique | Typical Saving | Tool Examples |
|---|---|---|
| Whitespace + comments only | 30-50% | This tool, simple regex passes |
| AST-based variable mangling | 50-70% | Terser, UglifyJS |
| Bundler with tree-shaking | 60-80% | esbuild, swc, Rollup |
| Minify + gzip transfer | 75-85% | Production CDN delivery |
| Minify + brotli transfer | 80-90% | Modern static hosts |
Frequently Asked Questions
Will this break my code?
It shouldn't, because the regex passes only touch whitespace, comments, and operator spacing. But there's no AST safety net, so if your source uses unusual constructs, run the output through Node or a browser before shipping. Common gotchas to test: ASI-dependent return statements, regex literals, JSX (which this tool will mangle if you forget to compile it first), and any code that relies on exact whitespace inside template literals.
Should I use this instead of Terser?
For one-off scripts, embedded widgets, or paste-and-go situations, yes. For application code that you're going to deploy, no. Terser does compression passes that this tool can't (variable mangling, dead-code elimination, constant folding) and its output is roughly half the size again. Most modern build tools (Vite, Next.js, esbuild, swc) include a Terser-equivalent step automatically.
Does this work on TypeScript or JSX?
No. Strip TypeScript types and compile JSX first using tsc, swc, or esbuild, then minify the resulting JavaScript. Running this tool directly on TypeScript will leave the type annotations in place but break the file by removing whitespace that the TypeScript parser depends on for line-based error recovery. Same logic applies to JSX: compile to React.createElement calls first.
Why minify if I'm using gzip anyway?
Three reasons. First, gzip happens on the wire, but the unminified version still sits in your build output and your CDN cache, costing storage. Second, parse and compile time on the client matches the size of the un-gzipped file, not the gzipped one, so minified JS starts running faster. Third, on slow CPUs (low-end Android) parse time dominates load time more than transfer, so smaller source genuinely matters.
Related Tools
CSS Minifier
Minify CSS by removing comments, whitespace and unnecessary characters. See original and minified size with savings percentage. Copy or download the result.
HTML Entity Encoder
Encode text to HTML entities or decode entities back to text. Handles named, numeric and hex entities. Bulk text support with instant copy to clipboard.
JSON Formatter & Validator
Format, minify and validate JSON with syntax highlighting. Shows error locations, key count, nesting depth and size stats