Where the bytes go
Renaming is the main event. A function full of userAccountBalance becomes a
function full of a, and that saving compounds across every reference. Comment
and whitespace removal is the visible part but the smaller one.
Expression rewriting is the third piece: if (a) { b() } becoming a&&b(),
true becoming !0. It is worth a few percent and is the reason a minifier
must parse rather than pattern-match.
What it cannot rename
Anything reachable from outside the file: exported names, global functions, object properties accessed as strings. Terser is conservative here by default because being wrong means a runtime error rather than a bigger file.
Code using eval or with defeats the analysis entirely — both let a name be
constructed at runtime, so nothing can be safely renamed.
Measure after compression
Minified JavaScript still compresses. Reporting the minified size alone overstates the benefit, because gzip would have removed much of the same redundancy on its own. If you are deciding whether a build step is worth it, compare the compressed sizes.
Questions
What does minification actually do?+
Three things: removes whitespace and comments, renames local variables to single letters, and rewrites some expressions into shorter equivalents. The first is cosmetic, the second is where most of the saving comes from, and the third is why a minifier needs to understand the code rather than the text.
Is it safe?+
For ordinary code, yes — Terser only renames identifiers it can prove are local. It breaks on code that reaches names by string: eval, with, and anything doing a lookup by property name that a bundler cannot see. Those are rare and worth avoiding regardless.
Should I compare this to my bundler's output?+
Your bundler almost certainly runs Terser or something equivalent already, so the numbers should be close. This page is for a standalone snippet: an inline script, a bookmarklet, a tag you are pasting into someone else's site.
What about gzip?+
Measure after compression, not before. Minification and gzip overlap — both exploit repetition — so a 40% minification saving might be 15% once compressed. The uncompressed figure flatters the result.