JavaScript Minifier
A small example shrinks from 68 to 40 bytes (41.2% smaller) by removing comments and whitespace only: function hello(name){return"Hi, "+name;}
How to use
- Paste your JavaScript into the input box.
- Leave "Keep license comments" on if your file has a header that must stay. Turn it off to remove every comment.
- Read the size before and after, then copy the minified code.
How it works
This tool splits the code into tokens and writes them back with the least whitespace that still reads the same. It never changes a token, so strings, regular expressions, template literals, numbers and names come out exactly as they went in.
It does not rename variables, shorten property names, remove dead code or convert syntax. That is why the saving is smaller than with a full minifier.
A space stays wherever two tokens would otherwise merge, as in "return x", "a in b", "a + +b" and "1 .toString()". A slash is read as a regular expression or as division from the token before it, including after the closing bracket of an if, while or for header.
Line breaks are removed only where that cannot change the program, for example after an opening bracket, a comma, a semicolon or an operator. Where JavaScript could insert a semicolon automatically, such as after a statement without a semicolon, after return, or before a line that starts with ( or [, the line break stays. Code that already ends statements with semicolons shrinks to very few lines.
The tool warns about an unterminated string, template or comment, and about braces that never close. Check the original when you see a warning.
FAQ
Will minified code behave the same?
It should, because only whitespace and comments change and the tokens stay identical. Line breaks that automatic semicolon insertion depends on are kept. Run your tests on the result before you ship it, as with any build step.
Why are some line breaks still there?
JavaScript may insert a semicolon at a line break. When a statement has no semicolon, joining it to the next line could change the meaning or cause a syntax error, so the break is kept. Adding semicolons to your source lets the tool join those lines.
Does it rename variables like Terser or esbuild?
No. It only removes whitespace and comments. For the smallest possible bundle use a build tool for production, and use this page for quick snippets, bookmarklets and checking sizes.
Does it handle regular expressions and template literals?
Yes. A regular expression such as /a b[/]/g and a template such as `x ${ y } z` are copied as they are, and code inside ${ } is minified. The one limit is a regular expression literal that starts a line right after a closing bracket that is not an if, while or for header, which is rare.
Does it support modern syntax and TypeScript?
It reads modern JavaScript syntax such as arrow functions, classes, optional chaining and private fields, since it never needs to understand them. It does not parse TypeScript or JSX, so type annotations and tags may be handled as plain text and are not checked.
Is my code uploaded?
No. Everything runs in your browser.