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…

What does a formatter or minifier change in code?

A formatter changes layout — whitespace, line breaks and indentation — so that HTML, CSS or JavaScript reads consistently, and some also normalise details the language treats as equivalent, such as HTML tag-name case or attribute quotes; a minifier removes what the browser does not need — comments, whitespace, optional semicolons — and may rewrite values into shorter equivalents such as #fff for #ffffff. Neither is meant to change what the code does, but review the diff before you commit it: an option that reorders code, such as sorting CSS properties, can change which declaration wins, and a lower-cased tag name breaks a case-sensitive framework component such as <MyComponent>.

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.

References