JavaScript Minifier
Removes comments and whitespace without touching strings or regular expressions.
Loading the tool…
How to use this tool
- Paste the JavaScript, or load a .js file with the picker.
- Leave line breaks on unless you are certain every statement ends in a semicolon.
- Select Minify.
- Download the result as script.min.js, or copy it.
What javascript minifier does
A minifier that works by regular expression will eventually eat a brace inside a string, or mistake a division for a regular expression and swallow half a file. This one tokenises properly first: strings, template literals including nested substitutions, regular expression literals, and both comment forms are all recognised as units before anything is removed, so their contents are never touched.
What is removed is comments and whitespace that carries no meaning; a space is kept wherever dropping it would join two tokens into one. Line breaks are kept by default, because JavaScript inserts semicolons at line ends and removing the newlines from code that relies on that changes what it does. Turn them off for the smallest possible output when you know the source is fully semicolon-terminated. This is a size reducer, not a name mangler — it will not rename your variables, so the result is still readable and still debuggable.