Minify
JavaScript Minifier
JavaScript minify is where careless tools embarrass themselves. Spaces inside strings are data. A comment can sit next to a regex. This pass is conservative: comments out, extra space out, syntax still standing. Great for snippets. Not a stand-in for Terser in a real bundler.
Drop a file on the left. Drafts stay in this browser. Shortcut: Ctrl or Cmd + Enter to run.
How this javascript minifier works
- Paste or drop a .js file into the input on the left.
- Flip options if you see them (comments, indent, case). Defaults are the safe ones.
- Hit Run, or Ctrl / Cmd + Enter. Leave “Process on server” off unless you mean it.
- Read the status line, then copy, download, or jump to a related tool.
Conservative, on purpose
Terser, esbuild, SWC can rename locals, fold constants, drop dead branches. That needs a parse tree and guesses about the environment. An online box that claims all of that on random pasted code will eventually chew a library you like.
Identifiers stay yours. String contents stay put. Savings are smaller than a bundler. Surprises are smaller too. That trade is the point.
Right time of day
Good: a userscript, an analytics snippet you cannot rebuild, a gist, a bookmarklet (still test it). Bad: the whole React app, anything that leans on Function.toString(), anything you obfuscate and then call “secure.”
Need it ugly? The obfuscator is an honest delay tactic, not a vault. Need it readable again? Beautifier and formatter sit in related tools.
Frequently asked questions
What is a conservative JavaScript minifier doing?
It removes comments and extra spaces while trying not to touch strings or break tokens. function greet(name) {\n return "Hello, " + name;\n} becomes function greet(name){return "Hello, "+name;}. Notice "Hello, " kept its space. That space is inside a string. It is data.
Why not use Terser / esbuild for everything?
Those tools parse the language, rename locals, and drop dead code. They need a real build. A paste box that “renames variables” on random snippets will eventually mangle window.jQuery. Conservative minify is smaller savings, fewer horror stories.
Can JS minify break my code?
The classic trap is return\n{ ok: true }. JavaScript inserts a semicolon after return, so you return undefined and start a block. Minify that joins lines can also glue tokens: a + ++b needs its space. If a snippet uses Function.toString() or depends on exact source, skip minify.
What about regex literals and comments?
var re = /https:\/\//; is not a comment. // inside a regex is still a regex. A blunt “delete // to end of line” pass will eat the rest of the file. Token-aware minify is the difference between a tool and a prank.
Fun JavaScript semicolon fact?
Fun fact: ASI (automatic semicolon insertion) is why people put semicolons before IIFEs: ;(() => {})(). Minifiers that concatenate files still bump into that. One missing ; between files and you get }( as a function call. Charming, once.
Should I minify bookmarklets and inline scripts?
Bookmarklets want small, yes — then URL-encode. Inline <script> in HTML can minify, but HTML minifiers must not smash JS strings. If the script is a whole React app, use the bundler. If it is ten lines of analytics, a conservative minify is plenty.
Is minified JS faster to execute?
Usually it is faster to download. Engines parse compact JS well. The big wins are still less JS, code splitting, and not sending a 400 KB date library for format(date). Minify is hygiene, not a rewrite of your architecture.
Minify vs obfuscate vs uglify?
Minify = smaller, still JS. Obfuscate = harder to read, not secure. “Uglify” is the old family name for minify+mangle. If you need secrets, do not put them in JS. Anyone can pretty-print the bundle.