JavaScript Formatter
Format JavaScript with consistent indentation, spacing and statement breaks.
Strip comments and whitespace from JavaScript, safely.
JavaScript Minifier removes comments and unnecessary whitespace, which is the part of minification that is always safe. Strings, template literals and regular expressions are detected and passed through untouched, because a brace or a slash inside one looks exactly like code and a minifier that cannot tell the difference corrupts the file.
What this tool deliberately does not do is rename variables. Serious minifiers shrink files much further by turning descriptive names into single letters, and doing that correctly requires parsing the whole program and understanding every scope. Doing it almost correctly breaks code in ways that only show up in production, which is the worst possible place to find out.
So the expected saving here is modest: usually twenty to forty percent on commented source, and considerably less once gzip is applied. For a production build, use a proper minifier in your pipeline. For shrinking a snippet you are about to inline in a page, this does the job without risk.
The javascript minifier is used by writers, developers, students, marketers and anyone else who needs the job done once without installing software. Common cases include:
Because doing that safely requires fully parsing the program and resolving every scope, and getting it slightly wrong produces code that fails at runtime rather than refusing to build. A tool that cannot guarantee correctness should not take that risk with your code.
Usually twenty to forty percent on commented source, and less after gzip. A full minifier with renaming and dead code removal typically does two to three times better.
The transformations are byte-level and preserve semantics, so yes for the kind of script this is meant for. For a large application, a dedicated minifier in your build pipeline remains the right tool.
Optionally. Block comments beginning with an exclamation mark are kept when that option is on, which is the convention for licence headers you are required to retain.
Yes. Template literals, arrow functions, classes, optional chaining and the rest are all handled, because the tool works at the token level rather than needing to understand each construct.
No. Minification runs entirely in your browser.
If the javascript minifier is not quite what you need, these other free tools solve closely related problems.
Format JavaScript with consistent indentation, spacing and statement breaks.
Minify CSS by removing comments, whitespace and redundant characters.
Shrink HTML by removing comments and collapsing whitespace, safely.
Strip whitespace from JSON and compare original and minified sizes.
A three-pane editor with a live preview that updates as you type.