How to use it
Paste a script and this tool will minify JavaScript by removing comments, indentation and redundant whitespace. It reads the code token by token, so strings, template literals and regular expressions are never altered, and line breaks that automatic semicolon insertion depends on are kept. Variable and function names are not shortened, which keeps the output recognizable when you debug it. Everything happens in your browser.
How to minify JavaScript here
- Paste the code into the input box, from a single function to a whole file.
- Press "Run tool" or Ctrl + Enter to minify it.
- Check the character and byte count under the output to see what you saved.
- Copy the result into your page or file, then run it once to confirm it behaves as before.
Scope: a safe minifier, not a full optimizer
- Removed: line comments, block comments, indentation and spaces that carry no meaning.
- Preserved: comments starting with
/*!, which conventionally hold license notices, and a leading#!line. - Spaces that matter: kept where joining tokens would change them, as in
a+ +bortypeof z. - Line breaks: joined only where it is provably safe for automatic semicolon insertion.
- Not done: renaming (mangling), dead-code removal, constant folding, transpiling modern syntax and generating source maps. A build-time bundler does those; this page does not pretend to.
Worked example
A nine-line cartTotal(items, taxRate) function with a license header, two comments and normal indentation is 224 characters. After minification the header stays on its own line and the code becomes function cartTotal(items,taxRate){let total=0;for(const item of items){total+=item.price*item.qty;} followed by return total*(1+taxRate);} on a second line, 152 characters in all.
The line break before return is a deliberate safety margin. Joining it would be harmless in this case, but the minifier only merges lines when it can prove the meaning cannot change. You pay a byte; you never get a silently broken script.
Why semicolon-free code survives
JavaScript inserts semicolons at some line breaks on its own, and naive minifiers that glue every line together break that. Here is how this one handles the classic traps:
| Source | Output | Why |
|---|---|---|
let a = 1 / let b = 2 on two lines | let a=1 / let b=2, still two lines | Joining would produce a syntax error |
return / 42 on two lines | return / 42 | Joined, the function would return 42 instead of undefined |
i / ++ / j | Line breaks kept | The increment belongs to j, not i |
'Hello world' and /a b/g | Unchanged | Spaces inside strings and regexes are data |
One case surprises people: a line ending in const c = a followed by a line starting with (b) becomes const c=a(b). That is not the minifier's doing; JavaScript already parsed the source as a function call. If a line must start with a parenthesis or bracket, put a semicolon in front of it.
When to use this instead of a build tool
For an application, a bundler that renames variables and removes unused code will save more. This page is for quick jobs without a toolchain: a custom script field in a CMS, a small widget embedded in a landing page, a snippet sent to a client, or a bookmarklet. For bookmarklets, write every semicolon explicitly: browsers strip line breaks from URLs, so any break the minifier keeps for safety would be lost. Background reading: what is minification.
Privacy and related tools
Minification runs in JavaScript in your own tab; your code is not sent to the server, and the page only increments an anonymous usage counter. The tool does not validate syntax, so broken input produces broken output. To read minified code, use the JavaScript beautifier; for pages with inline scripts, the HTML minifier applies the same rules to every script block.