Skip to main content

JavaScript Minifier

Minify JavaScript by stripping comments and every byte of unnecessary whitespace. Strings, template literals and regular expressions are left byte-identical, and line breaks that Automatic Semicolon Insertion depends on are preserved.

Input

Drop a file or browse
One file · text
Or

Settings

Preserves /*! … */ and comments containing @license or @preserve.

Output

Minified JavaScript
 
Was this helpful?

Guides

Paste JavaScript and get back the same code with the comments and every unnecessary byte of whitespace removed. It runs as you type, handles modern syntax (template literals, optional chaining, classes, async/await), and is built to be correct first — it will never hand you back code that behaves differently from what you pasted.

How to use it

  1. Paste your JavaScript into the input box, or upload a .js file.
  2. Optionally turn off Remove comments to keep them, or turn off Keep license comments to strip even /*! … */ and @license banners.
  3. Copy the minified result or download it as a .js file.

What it does — and what it refuses to do

It removes comments and collapses whitespace. That is the whole transform, and it is applied through a JavaScript tokenizer rather than a pile of regexes, which is what makes it safe:

  • String literals, template literals and regular expressions come out byte-identical. A // inside "https://example.com//path" is not a comment. A / inside /https?:\/\//g is not a division. A ${ … } hole inside a template — even one containing another template — is left exactly as written.
  • Identifiers are never renamed. No mangling, no scope analysis, no true!0.
  • Semicolons are never removed or added.
  • Line breaks that Automatic Semicolon Insertion depends on are preserved. This is the subtle one, and it is where most home-made minifiers corrupt code.

What is the ASI problem?

JavaScript inserts semicolons for you at certain line breaks. Delete the wrong newline and the meaning changes:

function g() {
  return
  42
}

g() returns undefined, because ASI puts a semicolon after return. A minifier that joins those lines into return 42 has silently changed your program. This tool keeps that newline — along with any newline where the previous token could end a statement and the next could begin one, which is exactly the condition under which ASI fires. Semicolon-free code (standard style) survives intact.

Why is the output bigger than terser's?

Because it does less on purpose. Renaming local variables is where a real minifier gets most of its savings, and doing that correctly needs a full parser and scope graph. Guessing at it is how a minifier breaks eval, with, getters, and anything reflecting on Function.prototype.toString. If you need maximum compression for a production bundle, run terser or esbuild in your build pipeline. If you want a fast, private, no-install way to shrink a snippet, a bookmarklet, or an inline script — that is this tool.

You will also find that gzip or brotli on your server recovers most of the difference anyway.

Are there any known limits?

Two, both inherited from tokenizing without a full parse:

  • A regex literal placed directly after ) — as in if (a) /re/.test(b) — is read as division. Assign the regex to a variable if you hit it.
  • A regex containing an unescaped } inside a template literal's ${ … } hole can end the interpolation early.

Both are rare in real code, and neither will produce output that looks fine but misbehaves — you will get a parse error you can see.

Is my code uploaded anywhere?

No. Minification happens entirely in your browser. Your source is never sent to a server, never logged and never stored, and uploading a file reads it locally in the page. Safe for proprietary or unreleased code.

javascriptjsminifiercompressformatterweb

Love the tools? Lose the ads.

One payment clears every ad from your account, for good. No subscription, no tracking.