Free tools, no sign-up — everything runs in your browser.
ToolHub 1000Free online tools

JavaScript Minifier Guide: Comments, Whitespace and Strings

Learn what a basic JavaScript minifier safely removes and where it can still be caught out.

What is the JavaScript Minifier?

This tool strips line and block comments and collapses runs of whitespace, then trims spaces around braces, brackets, parentheses, semicolons and commas. Quoted strings, including template strings, are protected first so their contents are not altered. It is a basic minifier: it does not rename variables, remove dead code or handle every edge case, and regular expressions containing comment-like text can still confuse it, so check the result before shipping it.

How to use it

  1. Paste your JavaScript into the box.
  2. Click Minify JavaScript.
  3. Check the compact result before using it in production.

Worked example

For the sample, the comment is removed and the function collapses to one line, with spaces around braces and parentheses removed while the greeting string stays intact.

Why is my minified code still not tiny?

Because a basic minifier only removes comments and whitespace. Real size savings from renaming and dead-code removal need a full build tool.

Frequently asked questions

Does it rename variables?

No. Names are left exactly as written; only comments and whitespace are removed.

What can still go wrong?

Regular expressions that look like comments, and other unusual syntax, can confuse a basic minifier. Treat the output as a draft and test it.

Try the JavaScript Minifier free · All guides