Home / JavaScript tools / JavaScript minifier

JavaScript Minifier

Paste JavaScript and get a smaller version with comments and extra whitespace removed. See how many bytes you saved, before and after gzip.

Result

0Original (bytes)
0Minified (bytes)
0%Saved
0Gzipped (bytes)

What minifying does

Minifying makes a JavaScript file smaller so that it downloads and loads faster. This minifier removes comments, indentation, line breaks and every space that the language does not need. The code behaves exactly as before.

// Before
function add(a, b) {
  // sum of both
  return a + b;
}

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

Safe by design

JavaScript lets a line break end a statement, so deleting every line break can break code that has no semicolons. This tool keeps a line break wherever removing it could change the meaning, for example after return, or before a line that starts a new statement. Strings, regular expressions and template literals are never touched, and a space is kept wherever two words or two plus or minus signs would otherwise join into one.

Options

  • Remove comments: deletes line and block comments. A first line that starts with #! is always kept so that command line scripts keep working.
  • Keep license comments: keeps block comments that begin with /*! or contain @license or @preserve, which many licenses require you to retain.

The size report

The report shows the original size, the minified size, the percentage saved and the size after gzip, which is what most servers send over the network. Gzip is shown when your browser supports it. Sizes are in bytes of UTF-8 text.

What this minifier does not do

It removes whitespace and comments only. It does not rename variables, remove unused code or rewrite expressions, which is what tools such as Terser and esbuild do. Those tools shrink code further but need a full parser and are best run in your build. Use this page for quick jobs: a snippet, a bookmarklet, an inline script or a file that you want to compare before and after.

To read minified code again, use the JavaScript beautifier. To tidy code you are still writing, use the JavaScript formatter. The formatting guide explains when to use each.

Frequently asked questions

How do I minify JavaScript?

Paste your code into the box. The minified version appears at once, with the bytes saved. Copy it or download it as a .js file.

Is it safe to minify code that has no semicolons?

Yes. The minifier keeps a line break wherever removing it could change the meaning, so code that relies on automatic semicolons keeps working.

Does it rename variables?

No. It removes comments and whitespace only. For renaming and dead code removal, use Terser or esbuild in your build.

Can I keep my license comment?

Yes. Leave Keep license comments on and any block comment that starts with /*! or contains @license or @preserve is kept.