JavaScript minifier
Shrink JavaScript with a real parser, not a find-and-replace.
What JavaScript minification does
Three things, in increasing order of value. It strips comments and whitespace. It renames local variables to single letters, which is where most of the saving comes from. And it applies safe transformations — collapsing if/else into conditionals, removing unreachable code, folding constants.
Typical results are 30–60% before compression, and more on code with long descriptive names, which is to say on good code.
Why a parser is not optional here
JavaScript cannot be minified with regular expressions, and the attempt fails in ways that are hard to spot. The old version of this tool treated // inside a string as a comment, so const url = "https://example.com" became const url = "https: — silently destroying the rest of the line. It also collapsed newlines, which breaks automatic semicolon insertion and changes what the program does.
This uses terser, which parses the code into a syntax tree, transforms the tree, and prints it back. It cannot make either mistake because it never looks at the text.
What it will refuse
Syntactically invalid code is reported with the position rather than mangled. That is useful in itself — a minifier is a strict parser, so if it complains, the code genuinely has a problem.
Names that must survive
Only local names are shortened; globals, property names and anything reached by string lookup are left alone. Code that depends on Function.prototype.name, or on a class's own name at runtime, needs care — that is rare, but it is the one thing that breaks under mangling.
It runs in your browser
Your source is never uploaded, which matters for anything unreleased or proprietary.
Common questions
Will it break my code?
No. These are real parsers working on a syntax tree. The regex-based tool this replaces did break code, routinely.
Why did it reject my file?
A parser reports syntax errors rather than guessing. The message usually points straight at the problem.
How much smaller will it get?
Roughly 20–35% for CSS, 30–60% for JavaScript, 5–15% for HTML — before gzip.
Is minifying still worth it?
Somewhat. Compression recovers much of the same saving, though the two do compound.
Can it un-minify?
No. Variable names are gone for good — that is where most of the saving comes from.
Is my code uploaded?
No, it is processed in your browser.