Ask how much minification saves and you will find confident percentages everywhere, quoted as if they were properties of the technique. They are not. What a minifier can save is bounded by what it removes, and different tools remove different things. A minifier that only strips comments and whitespace can never save more than the comments and whitespace in your file, so the same tool saves a quarter of one snippet and nearly two thirds of another.

This guide answers the question with counted examples instead of borrowed benchmarks, using the free JavaScript Minifier on Ovatly. That tool removes comments and unnecessary whitespace from JavaScript in your browser, and shows you a size report for every file you paste. Two real counts below show the range, and the sections after them explain why the range is the answer.

Contents

  • Quick answer
  • What this minifier removes, and what it never touches
  • How to minify and read the size report, step by step
  • Worked example 1: the tool's own sample, counted
  • Worked example 2: a comment-heavy snippet, counted
  • Why the two percentages are so different
  • Limitations and honest boundaries
  • Common mistakes
  • FAQs
  • Conclusion

Quick answer

It depends entirely on how much of your file is comments and spare whitespace, because that is all this minifier removes. In the counted examples below, a lightly commented two-line sample shrank from 78 to 57 characters, a saving of 21 characters or about 27 percent. A snippet carrying a full-line comment shrank from 80 to 30 characters, a saving of 50 characters or 62.5 percent. Neither number is typical of anything except its own input. Paste your file into the JavaScript Minifier and read its size report: that is the only honest answer for your code.

What this minifier removes, and what it never touches

The tool removes comments and unnecessary whitespace. That is the whole list, and it is a deliberate design choice rather than a missing feature. Before removing anything, it tokenizes the code, which means it understands which parts are code and which parts are text. Text inside strings, template literals and regular expressions is never mistaken for a comment, so a // sequence inside a URL string is treated as data and kept. Template literals are preserved verbatim, including the expressions inside them. Newlines that JavaScript's automatic semicolon insertion depends on are also kept, so the minified code parses the same way the original did.

Just as important is what it does not do. It does not shorten variable names, remove dead code or bundle modules. It is a whitespace and comment minifier, not an optimizing compiler. An optimizing tool such as terser goes further: it also renames variables, folds constants and removes dead code, which is why terser's saving on the same file is bigger. The trade is predictability. This tool never rewrites your program, so the output is your code with the air let out, nothing more.

How to minify and read the size report, step by step

  1. Paste your JavaScript into the input box.
  2. Press Minify JavaScript.
  3. Check the size report to see the saving. This is the number this whole guide is about, measured on your actual file.
  4. Copy or download the minified code.

If the input contains an unterminated string, template literal, block comment or regular expression, the tool reports it as an error instead of silently mangling the output. Treat that as a free syntax check: fix the code first, then minify.

Worked example 1: the tool's own sample, counted

The minifier's documentation uses this input, which pairs a real comment with a string that merely looks like one:

const url = "https://example.com//not-a-comment"; // real comment
const x = 1;

Counted character by character, that input is 78 characters including the line break. The output is a single line:

const url="https://example.com//not-a-comment";const x=1;

The output is 57 characters. The saving is 21 characters, about 27 percent of the original. Look at where those 21 characters came from: the trailing comment and the spaces around the two assignment operators. The // inside the URL survived untouched, because the tokenizer knew it was string content, not a comment. Nothing was renamed: url and x keep their names, and both statements are still there.

Worked example 2: a comment-heavy snippet, counted

Now a small function written the way people write code they expect to maintain, with an explanatory comment and indentation:

// Add two numbers and return the result.
function add(a, b) {
  return a + b;
}

That input is 80 characters including line breaks. Minified under the same rules, comments and spare whitespace out, code untouched, it becomes:

function add(a,b){return a+b;}

The output is 30 characters. The saving is 50 characters, 62.5 percent of the original, more than double the percentage of the first example from exactly the same tool. The comment alone accounted for 41 of the input's 80 characters, over half the file. Remove the comment from the input and the same code would have shown a modest saving, closer to the first example.

Why the two percentages are so different

The variable is never the tool; it is the input. Savings track two things: comment density and formatting style. A file with long explanatory comments and generous indentation carries a lot of removable weight. A file that was already written compactly, with few comments and tight spacing, has little to give up, and minifying it saves little. This is also why any single percentage quoted for real websites should be distrusted: real codebases mix both kinds of file, plus code an optimizer could shrink further by renaming and dead code removal, which this tool deliberately does not do. The size report on your own file cuts through all of it, because it counts your comments and your whitespace, not an average of strangers' code.

Limitations and honest boundaries

The tool handles plain JavaScript only. JSX and TypeScript syntax need a real parser first, and pasting them will not work. One rare ambiguity is worth knowing: a regex literal appearing right after the closing brace of a block is treated as division, a corner every lightweight tokenizer has to resolve one way. And because the tool never rewrites your program, it will always save less than an optimizing compiler on production code; for a production pipeline, a tool like terser goes further. What this minifier is for is the quick, predictable job: a snippet, a copied sample, a small script with no build step, minified safely in the browser with nothing uploaded. Layout discipline matters on the formatting side of the workflow too: our guide to common CSS readability mistakes covers the stylesheet version of the same habits.

More guides for working with code, markup and data live in the developer tools guides.

Common mistakes

  • Quoting a benchmark percentage as your expected saving. Your saving is the weight of your comments and whitespace. Measure your file instead.
  • Expecting renamed variables. Names stay as written. If output with shortened names is what you need, you need an optimizing compiler, not this tool.
  • Minifying code with an unterminated string or comment and shipping the result. The tool reports those as errors rather than mangling them; read the error and fix the code.
  • Editing the minified output afterwards. Minified code is a build product. Edit the readable source and minify again, or your fix disappears on the next pass.
  • Skipping tests because the tool is conservative. It only removes whitespace and comments that cannot change meaning, and still, run your test suite after minifying anything important.

FAQs

Is the minified output safe to run? The tokenizer is conservative: it only removes comments and whitespace that cannot change meaning, and preserves statement newlines so automatic semicolon insertion behaves as before. Still, run your test suite after minifying anything important.

Why is the saving smaller than terser? Terser also renames variables, folds constants and removes dead code. This tool deliberately avoids rewriting your program; it just removes comments and spare whitespace, so its saving is smaller and its behaviour easier to predict.

Does it support JSX or TypeScript? No. Paste plain JavaScript. JSX and TypeScript syntax need a real parser first.

What happens if my code has an unterminated string or comment? It is reported as an error instead of being silently mangled. Unterminated strings, template literals, block comments and regular expressions are all flagged, so a broken file fails loudly rather than shipping half-minified.

Does minifying remove the // inside a string by mistake? No. The tool tokenizes the code first, so text inside strings, template literals and regular expressions is never mistaken for a comment. In the worked example below, the // inside a URL string survives while the real comment next to it is removed.

Conclusion

How much does JavaScript minification save? On the evidence of the two counted examples: 21 characters out of 78 when the code is lean, 50 out of 80 when a comment does half the talking, and whatever your own file's size report says when you paste it. The percentage is a property of your code's comments and formatting, not a property of minification itself. Anyone quoting you one fixed number for all websites is selling something. Count your own file; it takes ten seconds.