JavaScript Minifier

Runs in browser Formatting

Reduce JavaScript size by stripping comments and unnecessary whitespace while preserving strings, regex literals and ASI-sensitive constructs. Shows the size savings.

Privacy: This tool runs entirely in your browser. Your input never leaves your device.
Loading tool…

How to use JavaScript Minifier

  1. Paste the JavaScript.
  2. Decide whether license comments (or all comments) should be kept.
  3. Copy or download the minified script.

JavaScript Minifier features

  • Strips comments and all unnecessary whitespace
  • Preserves line breaks that matter for automatic semicolon insertion
  • Keeps /*! license */ and @license/@preserve comments (optional)
  • Strings, template literals and regex literals are never modified
  • No renaming or code transformation — output stays debuggable
  • Displays original size, minified size and savings

JavaScript Minifier example

Minify a helper

Input:

// add numbers
function add(a, b) {
  return a + b;
}

Output:

function add(a,b){return a+b;}

Frequently asked questions about JavaScript Minifier

How is this different from Terser or esbuild?

This tool removes whitespace and comments only; it does not rename variables, inline constants or drop dead code. That keeps the output readable in stack traces and makes it safe for quick copy-paste use.

Is the output safe with automatic semicolon insertion?

Yes. A line break is kept wherever removing it could change the meaning (for example before a line starting with ( or [ or a template literal), so ASI-dependent code keeps working.

Can I keep the license header?

Comments starting with /*! or containing @license / @preserve are kept by default. Untick the option to remove them too.

What savings should I expect?

Typically 20–40% on hand-written code, mostly from indentation and comments. The stats panel shows the exact bytes saved.

Technical notes

A safe minifier only removes what cannot change semantics. Whitespace between two identifier characters is reduced to one space, "+ +" and "- -" sequences keep their space, and a newline is kept between an expression end and an expression start (for example before "(" or "[") so ASI rules still apply.