JavaScript Minifier - Conservative Compression That Respects Your Code
Naive minifiers that treat JavaScript as plain text break code the moment a string contains "//" or a regex contains a quote. This tool lexes your code into tokens first and only then decides what can safely be removed.
How to use the JavaScript Minifier
- Paste or type your JavaScript into the top box.
- Click Minify JavaScript.
- Check the size panel to see how much was saved.
- Copy the result or download it as a .js file - and, as with any minifier, run your code once to confirm it behaves the same.
How it works
The tool first splits your code into tokens: identifiers, numbers, strings, template literals, regular expressions and punctuation. Comments are recognised during this scan and dropped, and the scanner knows the difference between a division sign and the start of a regex, and never looks inside a string for comment markers. Tokens are then re-joined, adding a separating space only where removing it would change the meaning - between two words, between a plus and another plus, and so on. Newlines are kept wherever JavaScript's automatic semicolon insertion makes them meaningful, most importantly after return, break and continue, and before a leading ++ or --.
Worked example
A commented utility function of about 400 bytes typically compresses to around 260 bytes - roughly a third smaller - while a string like "see https://example.com // docs" inside it comes through completely untouched.
Frequently Asked Questions
Is this JavaScript minifier free?
Yes - completely free, with no sign-up, no size limit and no daily cap.
How is this different from a full build-tool minifier?
Build tools like Terser also rename variables and rewrite code, which squeezes out a few more percent. This tool is deliberately conservative: it never renames anything and never rewrites expressions, so the output is easy to eyeball and safe for quick one-off use.
Can it break my code?
It is designed not to: strings, template literals and regex literals are protected, and meaning-carrying newlines are preserved. No minifier can promise perfection on every exotic pattern, so always run your test suite or open the page once after minifying - that advice applies to every minifier, including ours.
Does it handle regular expressions and template literals?
Yes. The tokenizer recognises regex literals (including character classes and escapes) and template literals, including nested ${ } expressions, and carries them through unchanged.
Is my code uploaded to a server?
No. Tokenising and minifying happen 100% in your browser. Your source code never leaves your device.
Related Developer Tools
CSS Minifier & Beautifier
Minify CSS to shrink file size, or beautify it back into readable, indented code.
JSON Formatter
Validate, pretty-print and minify JSON, with the exact position of any error.
Regex Tester
Test regular expressions live - matches highlighted, capture groups listed, count shown.