JavaScript

JavaScript Minifier

Removes comments and whitespace without touching strings or regular expressions.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the JavaScript, or load a .js file with the picker.
  2. Leave line breaks on unless you are certain every statement ends in a semicolon.
  3. Select Minify.
  4. 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.

Frequently asked questions

No. The source is tokenised before anything is removed, so strings, template literals including nested substitutions, regular expression literals and both comment forms are recognised as whole units and their contents are never touched. That is the difference between this and a minifier built out of regular expressions.

Because JavaScript inserts semicolons at line ends, and removing a newline from code that relies on that changes what the code does. Keeping the breaks still removes the comments and all the indentation, which is most of the saving. Turn them off when you know every statement is properly terminated.

No. This is a size reducer, not a mangler. Renaming requires full scope analysis and it is the step most likely to break code that uses eval, with, or reflection over its own names. The result stays readable and stays debuggable.