The title of this guide names three things a JavaScript minifier is supposed to remove: comments, whitespace and names. For the free JavaScript Minifier on Ovatly, two of those claims are true and one is not, and the honest place to say so is right at the start. This tool removes comments and unnecessary whitespace. It does not remove or shorten names: your variable and function names come out exactly as you wrote them. This guide walks through each of the three categories, what happens to it, and why the third one is left alone on purpose.
Contents
- Quick answer
- Comments: removed, once the tool knows they are comments
- Whitespace: removed, except where meaning depends on it
- Names: not touched, and why
- How to minify with the tool, step by step
- Worked example: what changes and what survives
- Limitations and alternatives
- Common mistakes
- FAQs
- Conclusion
Quick answer
Paste JavaScript into the JavaScript Minifier and press Minify JavaScript, and two things come out: comments, and whitespace that carries no meaning. Names do not come out and are not shortened; url stays url, and a function keeps the name you gave it. Renaming variables is part of what optimizing minifiers like terser add on top, along with folding constants and removing dead code. This tool deliberately avoids rewriting your program, and everything runs in your browser.
Comments: removed, once the tool knows they are comments
Comments are the clearest win. They exist for readers, the browser ignores them, and they can be a large share of a well-documented file. The minifier strips them, both the line comments and the block comments, as part of its single pass over the code.
The subtlety is knowing what counts as a comment. A naive find-and-replace would delete everything after a // wherever it appears, including inside a string where those characters are data. This minifier tokenizes the code first, so text inside strings, template literals and regular expressions is never mistaken for a comment. A // that is part of a URL inside a string survives; a // that starts a real comment does not. The same care applies in reverse: if a string, template literal, block comment or regular expression is unterminated, the tool reports an error instead of silently mangling the output.
Whitespace: removed, except where meaning depends on it
Most whitespace in JavaScript is layout: indentation, blank lines, spaces around operators. None of it changes what the code does, so it comes out, which is why minified code collapses onto very few lines.
Some whitespace is load-bearing, and a careful minifier keeps it. JavaScript's automatic semicolon insertion means certain statement-ending newlines affect how code is parsed, so those newlines are preserved and statements still end where they ended before. Template literals are the other exception: their contents are literal text, including any spacing and line breaks you typed, and the expressions inside them, so they are preserved verbatim and never reshaped. One rare ambiguity is worth knowing: a regex literal appearing right after the closing brace of a block is treated as division, a call every lightweight tokenizer has to make one way or the other.
Names: not touched, and why
Names are where this tool stops, deliberately. Shortening calculateInvoiceTotal to a single letter would save real bytes, and it is the first thing an optimizing minifier does. It is also a rewrite of your program: every reference has to be renamed consistently, scopes have to be analysed, and names that other code depends on, such as exported functions or properties read by name, have to be left alone or the program breaks in ways that only show up at runtime.
This minifier avoids that whole class of risk. Its own description of the difference is direct: terser also renames variables, folds constants and removes dead code, while this tool just removes comments and spare whitespace. The trade is a smaller saving in exchange for output you can trust to be the same program. If your build already runs an optimizing compiler, use it for production; this tool is for the quick, safe pass on code you paste by hand.
How to minify with the tool, step by step
- Paste your JavaScript into the input box.
- Press Minify JavaScript.
- Check the size report to see the saving.
- Copy or download the minified code, and keep the original readable version as the one you edit in future.
Worked example: what changes and what survives
The minifier's own example puts all three categories in two lines. The input is:
const url = "https://example.com//not-a-comment"; // real comment
const x = 1;
The output is:
const url="https://example.com//not-a-comment";const x=1;
Read it against the three categories. Comments: the real comment at the end of the first line is gone. Whitespace: the spaces around the = signs are gone, because they carry no meaning. Names: url and x are untouched, exactly as written. And the detail that proves the tokenizer is doing its job: the // inside the string survives, because it is data, not a comment. Nothing in the output was renamed, folded or removed as dead code, because the tool does none of those things.
Limitations and alternatives
The limits follow from the design. There is no dead code removal and no bundling of modules, so unused functions and separate files stay exactly as they are. The input must be plain JavaScript; JSX and TypeScript syntax need a real parser first. And because names are never shortened, the saving will be smaller than an optimizing compiler achieves on the same code, sometimes much smaller on code with long, descriptive names and few comments.
When you need those extra steps, the alternative is a tool like terser inside your build pipeline, which renames variables, folds constants and removes dead code as part of your normal release process. The two are not rivals: the pipeline tool is for production builds, and this browser tool is for a fast, predictable pass on a snippet you are handling manually.
Common mistakes
- Expecting names to shrink. If you minify here and your long variable names survive, the tool has not failed; renaming was never part of the job.
- Comparing the saving with terser and concluding something is broken. The gap is the renaming, constant folding and dead code removal you chose not to run.
- Editing the minified output later. Keep the readable original as your source; minified code with comments stripped is the wrong place to make changes.
- Pasting JSX or TypeScript. Plain JavaScript only; the newer syntaxes need a parser before a tool like this can touch them.
- Assuming every
//is deleted. Inside a string it is data and it stays, which is correct, and checking the worked example above is the quickest way to see it.
FAQs
Does this minifier shorten variable names?
No. Names stay exactly as written. The tool removes comments and spare whitespace and deliberately avoids rewriting your program; shortening names is part of what optimizing minifiers like terser do instead.
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.
Is the 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.
What happens to template literals?
They are preserved verbatim, including the expressions inside them, so they are never reshaped.
Does it support JSX or TypeScript?
No. Paste plain JavaScript. JSX and TypeScript syntax need a real parser first.
Conclusion
Comments come out, whitespace comes out where it is safe, and names stay put, by design. Knowing which of the three a given minifier actually does tells you what saving to expect and which tool belongs in your pipeline. For the same workflow applied to a real site file, read How to Minify JavaScript for a WordPress Site, and browse the other developer tools guides for more walkthroughs in this series.