JavaScript Minifier — Remove White Space and Comments Safely
Remove comments and redundant whitespace from JS snippets locally.
300 → 281 bytes (6.3% smaller).
- The code is read token by token: regexes are told apart from division, template literals with nested ${…} and quoted strings are left alone, and line breaks that decide automatic semicolons (return, ++, --) are kept.
- Variable names are not changed and /*! … */ licence comments stay. The output is tested with esbuild: the original program and the minified one are exactly the same.
When to use the JavaScript Code Minifier & Whitespace Stripper
Smaller scripts without a build tool
For small scripts on static sites, widgets or bookmarklets, this minifier removes comments, spaces and line breaks that are not needed. The size before and after, the percentage saved and the gzip size show at once.
Automatic semicolons stay right
Line breaks that decide what the code means, such as after return or before ++, are not removed. Neither are the spaces in a - -b and a + ++b, because without them the meaning changes.
Tested with esbuild
Every result is tested with esbuild: the original program and the minified one print as exactly the same code. Testing uses pdf-lib, preact, jsQR and dozens of this site's scripts.
Licence comments stay
Comments starting with /*! usually hold a licence and are kept. Variable names are not shortened, so error messages and searches in the code stay readable.
Frequently asked questions
Why is it not as small as a build tool's output?
Build tools also rename variables and rewrite code. This tool deliberately removes only spaces and comments so the program stays exactly the same.
Is the output safe for inline scripts in HTML?
Yes. Text such as '</script>' inside a string stays intact and string contents are never changed, so a script that was safe to inline before is still safe after minifying.
Can TypeScript be minified?
This minifier is for JavaScript. Compile TypeScript to JavaScript first, then minify the result.
How is the gzip size measured?
Your browser compresses the output with gzip through CompressionStream and shows its size.
Is my code uploaded?
No. Minifying runs in your browser.
Similar tools
- JavaScript / TypeScript Code BeautifierRe-format dense JavaScript code blocks with balanced braces and indentation.
- HTML Beautifier & Indentation PrettifierRe-indent messy single-line HTML markup into readable nested element trees.
- HTML Whitespace & Comment MinifierCompress HTML documents by removing redundant whitespace & HTML comments.
- HTML to Clean GitHub Markdown ConverterConvert headings, links, bold/code tags & lists from HTML into clean Markdown.