UTILS.
100% in-browser
🗜️

JavaScript Minifier

Shrink JavaScript by stripping comments and unnecessary whitespace while safely preserving strings, template literals, and regex — runs locally in your browser.

— output appears here —

About this tool

The JavaScript Minifier reduces the size of a script by removing comments and collapsing unnecessary whitespace and newlines, then reports the byte savings. It is a fast, dependency-free way to shrink a small script or snippet before pasting it somewhere size-sensitive. All processing is local — the code is treated purely as text and never executed, so there is no eval and nothing is uploaded.

This is a conservative, token-aware minifier. It scans the source into tokens, correctly stepping over the interiors of strings, template literals, regular expressions, and comments, so their contents are preserved byte-for-byte. Comments are dropped (or kept, via the toggle), and runs of whitespace are removed everywhere except where a space is genuinely required — between two identifier/number/keyword tokens (so 'return a' never becomes 'returna') or between two operator characters that would otherwise fuse (so 'a + +b' keeps its space). A regex literal following a keyword also keeps its separating space.

Because it does not rebuild an abstract syntax tree, it does not rename variables or perform dead-code elimination — it only removes what is provably safe to remove. It also collapses newlines, so code that relies on automatic semicolon insertion across line breaks should already use explicit semicolons. The panel shows original size, minified size, and the percentage saved.

Frequently asked questions

Does it rename variables or compress logic?
No. This is a conservative whitespace-and-comment minifier, not a full compressor. It does not mangle variable names, fold constants, or remove dead code — it only strips comments and non-essential whitespace, so the output stays easy to diff against the source.
Are my strings and regex safe?
Yes. The minifier tokenizes the source and preserves the interiors of strings, template literals, and regular expressions exactly. Spaces and comment-like text inside them are never touched, so the minified code behaves identically.
Could minifying break my code?
It collapses newlines, so scripts that depend on automatic semicolon insertion across line breaks could change meaning. If your code already uses explicit semicolons — as most does — the output is equivalent. When in doubt, test the minified result.
What do the size numbers mean?
After minifying, the tool measures the original and minified source in UTF-8 bytes and shows both plus the percentage reduction, so you can see exactly how much smaller the script became.

More tools