JavaScript Minifier

Remove JavaScript comments and redundant whitespace while preserving ASI semantics.

  • Runs locally in your browser
  • No upload required

Try it

Paste JavaScript. Newlines that affect ASI are preserved.

Minified JavaScript
function f(a){return a+1;}
Size
44 → 26 characters (18 saved)

Supported formats

Input
text, boolean
Output
text

Privacy

Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.

Processing
In your browser
Privacy level
Browser only

Reduced 44 to 26 characters of JavaScript.

How it works

  • Removed comments.
  • Reduced inter-token whitespace to the minimum that keeps tokens separate.
  • Kept a newline wherever removing it could change automatic semicolon insertion.
  • Strings, template literals, regular expressions and comment contents are never altered.
  • Identifiers are not renamed and no semantic transform is performed.
  • Minifying the result again changes nothing.

Methodology

  1. Tokenise the script, recognising strings, templates, regexes and comments.
  2. Drop comments (when enabled) and join the remaining tokens with the smallest safe separator.
  3. Preserve a newline at each automatic-semicolon-insertion hazard.

Usage

  1. Paste or type JavaScript.
  2. Choose whether to remove comments.
  3. Run the minifier and copy the smaller script.

Examples

These are examples, not current values: they use fixed inputs, while the interactive tool computes live results in your browser.

Whitespace and comments removed

jsonSelect to copy
{
  "text": "function f ( a ) {\n  return a + 1; // inc\n}\n",
  "removeComments": true
}

ASI newline preserved

jsonSelect to copy
{
  "text": "return\n(1)",
  "removeComments": true
}

Regex and template preserved

jsonSelect to copy
{
  "text": "const re = /a\\/b+/g; const t = `x ${1 + 2}`;",
  "removeComments": true
}

Limitations

Minification without mangling

Aggressive minifiers are risky. This one deliberately stops at comments and whitespace: the token stream is unchanged, so the behaviour is unchanged and every risk is avoided.

Frequently asked questions

Can minifying change what my script does?
No. A newline is kept wherever removing it could change automatic semicolon insertion, and all token contents are preserved.
Does it rename my variables?
No. It performs no semantic transform; identifiers are left exactly as written.
Is my code uploaded?
No. The script is processed entirely in your browser.

Sources

  1. ECMAScript Language Specification — Ecma International
  2. MDN Web Docs — Automatic semicolon insertion — MDN