JavaScript Minifier

Compress JavaScript files for faster page loads.

Why this doesn't squash everything onto one line

JavaScript has a feature called automatic semicolon insertion that can silently change what your code does if lines get joined together without care - a safe general-purpose minifier needs to actually parse the syntax to avoid that trap, not just push text around with regular expressions. This tool strips comments and trims extra whitespace, which is genuinely safe to do blindly, and deliberately leaves line breaks alone rather than risk that class of bug.

What it safely removes

Single-line and block comments are stripped entirely, and leading/trailing whitespace on each line is trimmed - both changes that can never alter what the code actually does, since comments have no runtime effect and whitespace outside of strings is never semantically meaningful in JavaScript. The minifier carefully tracks whether it's currently inside a string or template literal so it never accidentally strips something that merely looks like a comment inside quoted text. It also recognises when a / opens a regex literal rather than division or a comment, so patterns like /^https?:\/\// survive intact instead of being mistaken for the start of a comment.

What a real production minifier does that this doesn't

Tools like Terser or esbuild parse your code into a full syntax tree, which lets them safely rename local variables to shorter names, remove genuinely dead/unreachable code, and join lines together with full knowledge of exactly where that's safe to do - none of which a regex-and-string-scanning approach like this tool's can do reliably. For an actual production build pipeline, use one of those real tools; this one is for a quick, safe size reduction on a snippet you're sharing or testing.

The savings percentage shown

After minifying, the tool reports exactly how many characters were removed as a percentage - useful context for understanding that comment-and-whitespace stripping alone, while completely safe, achieves meaningfully less size reduction than a real syntax-aware minifier would on the same code.

Domande frequenti

Is this safe to use on production code?

The comment-stripping and whitespace-trimming it does are safe, but it won't shrink your code nearly as much as a real build-tool minifier like Terser or esbuild, which understands JavaScript syntax rather than just text.

Why doesn't it remove line breaks like the CSS minifier does?

JavaScript can break if semicolons are missing and lines get joined incorrectly (automatic semicolon insertion). Leaving line breaks in place avoids that risk entirely.

Will this tool ever change what my code actually does?

No - it only removes comments and surrounding whitespace, both of which have zero effect on how JavaScript executes. It also correctly tells regex literals apart from comments and division (so a pattern like /\/\// is left intact), using the same approach real JS tokenizers use rather than a full parser - reliable for virtually all real-world code, though not a mathematical guarantee the way a syntax-aware tool like Terser is.

Why would I use this instead of just skipping minification for a small snippet?

For a quick size check or sharing a cleaner version of a snippet, this gives an instant, safe reduction without needing to set up a full build tool - useful for something lighter-weight than a production bundling pipeline.

Does this handle modern JavaScript syntax like arrow functions and template literals?

Yes - since it only strips comments and whitespace rather than parsing the code's structure, it works the same regardless of which JavaScript syntax features (arrow functions, template literals, async/await, and so on) your code uses.

Altro in Technical SEO & Site Management