JavaScript Minifier
Remove JavaScript comments and redundant whitespace while preserving ASI semantics.
- Runs locally in your browser
- No upload required
Try it
Supported formats
Privacy
Runs entirely in your browser. Your input is never uploaded, stored, or sent to a third party.
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
- Tokenise the script, recognising strings, templates, regexes and comments.
- Drop comments (when enabled) and join the remaining tokens with the smallest safe separator.
- Preserve a newline at each automatic-semicolon-insertion hazard.
Usage
- Paste or type JavaScript.
- Choose whether to remove comments.
- 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
{
"text": "function f ( a ) {\n return a + 1; // inc\n}\n",
"removeComments": true
}ASI newline preserved
{
"text": "return\n(1)",
"removeComments": true
}Regex and template preserved
{
"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
- ECMAScript Language Specification — Ecma International
- MDN Web Docs — Automatic semicolon insertion — MDN
Send feedback
Tell us if this tool helped, report a problem, or suggest a tool. Only the message you type is sent — never the input you used in the tool.
Was this tool useful?
Prefer to write to us directly? See the contact page.