How to minify JavaScript
Minifying JavaScript removes comments and collapses whitespace, producing a smaller file that behaves the same. It is a quick way to shrink an inline script or a small snippet without setting up a toolchain.
The transform runs in your browser. It is a scanner rather than a full parser: strings and template literals are protected, comments are dropped, and whitespace outside them is collapsed. That design is what makes it instant and also what sets its limits.
- Paste your JavaScript into the input box.
- Confirm your code terminates statements with semicolons, because newlines are collapsed and code relying on automatic semicolon insertion will break.
- Read the minified output and compare the byte counts.
- Diff the output against the input if the code contains regular expression literals, since those are not tracked by the scanner.
- Run the result before you ship it, and for anything going to production, use esbuild or terser in your build pipeline instead, so you get identifier renaming and a source map.