DEV

JavaScript Minifier

Shrink a script for production by removing comments and unneeded whitespace. Strings, regular expressions and template literals are left untouched.

INPUT
OUTPUT

          

How it works

The minifier reads your script token by token — strings, template literals, regular expressions, words and punctuation — then writes it back without comments, indentation, or any whitespace the JavaScript grammar doesn't need. Because it understands those token types, text inside a string or a regex is never altered.

Line breaks are handled conservatively. JavaScript sometimes treats a line break as the end of a statement (automatic semicolon insertion), so a break is only removed where doing so provably can't change the meaning — for example after an opening bracket or a comma. Elsewhere it stays, which keeps scripts that omit semicolons working.

What this minifier doesn't do

It does not rename variables or functions, and it doesn't remove dead code. That's why savings are typically 20–40% rather than the 60%+ you'd see from Terser or esbuild. If you ship a large app, use a build tool with real mangling; for a snippet, a bookmarklet or a single script file, this is fast and low-risk.

Test the output before you deploy it. Keep your original source, run the minified version, and confirm it behaves the same. Everything happens in your browser — your code is never uploaded.

Frequently asked

Will minifying break my JavaScript?

It shouldn't. Only comments and unnecessary whitespace are removed, and line breaks are kept wherever removing them could change how the code is parsed. Even so, test minified code before shipping it, and always keep your original source.

Why is the output not as small as Terser or UglifyJS?

Those tools also shorten variable and function names and rewrite code. This tool only removes comments and whitespace, so it is safer for quick jobs but saves less.

Does it support modern JavaScript?

Yes. Arrow functions, const/let, classes, template literals (including nested ${} expressions), async/await and regex literals are all handled. Only syntax the tool can't read as tokens, such as an unterminated string, produces an error.

What happens to license comments?

Comments that begin with /*! are treated as licence notices and kept by default, on their own line at the top of the output. Untick the option to remove them too.