JS Minifier
Minify JavaScript with terser: real parsing, compression and name mangling, ES6 and modules, with parse errors located precisely.
JS Minifier workspace
Source Editor
Press Ctrl/Cmd + Enter to run.
Your draft is kept in this tab only (sessionStorage) and disappears when the tab closes. .
Result Console
Using JS Minifier
Paste your JavaScript into the editor, or press Load example to try it on a sample module.
Press Minify JavaScript, which loads terser on demand and parses your source.
If a parse error appears, fix the reported line and column and run it again.
Read the before and after byte counts, then copy or download the compressed output.
Terser parses the source into a syntax tree, folds constants and removes unreachable code, then renames local bindings before printing it back out. It is dynamically imported at the moment you press the button, so the library is only downloaded by people who actually use this page.
JavaScript Minifier
Paste JavaScript, press Minify JavaScript, and terser runs over it in your browser. The library only loads at the moment you press the button, so nobody who never touches this tool downloads it.
What terser does to your code
It works in order. First it parses the source into an abstract syntax tree, so from then on it's reasoning about statements and expressions instead of raw text. Then it compresses: dead code after a return is dropped, if (true) branches are folded, constants are propagated, and sequences of statements are merged into expressions. Finally it mangles local identifiers, so function calculateTotalWithTax(basePrice) becomes function n(t) inside its own scope, while anything you export keeps its name.
Comments are stripped. ES6 and later is fully supported, including arrow functions, classes, template literals, optional chaining, async/await, and module syntax with import and export.
The panel reports bytes before, bytes after, and the percentage saved. Typical application code ends up somewhere between 40% and 60% smaller, and mangling contributes more of that than whitespace removal does.
Why it has to be a parser
Before the rebuild this page was three regular expressions. It really did each of these:
const u = "https://example.com/api"; -> const u = "https:
const re = /a\/\/b/; -> regex literal destroyed
const t = `line one
line two`; -> template literal rewrittenThe first is the classic. // inside a string isn't a comment, but a pattern that hunts for // can't know that, so the rest of the line got deleted. The second is the same mistake inside a regex literal. The third mangled a multi-line template, where every newline is significant.
A fourth failure did no visible damage until runtime. Removing newlines between statements breaks automatic semicolon insertion, so code that relies on ASI stops meaning what it meant, and the resulting error turns up somewhere unrelated. Meanwhile the page claimed lexical parsing, AST traversal and worker-based processing, and none of those existed.
Minification is a compiler problem. Anything short of a parser will eventually corrupt perfectly valid code, and it'll do it silently.
When the parse fails
Terser won't minify what it can't parse, and it won't guess either. A syntax error is reported with the line and column where the parser gave up. That's where the parser noticed the problem, which is often a line or two after the missing brace or stray comma that caused it, so read upward from there.
That makes the tool a passable syntax check: if your file minifies, it parses.
Where this fits, and where it doesn't
Minification runs on the main thread. For a component, a utility module or a snippet you're about to inline, you won't notice it. For a bundle of several megabytes it's the wrong place entirely, and that has nothing to do with this page. Production minification belongs in a build step, where esbuild, SWC or terser itself runs over your whole dependency graph, produces source maps, and does it again on every commit. No source map is generated here, so you wouldn't want to debug the output in a browser.
The realistic uses are one-offs: shrinking a snippet for a CMS field, checking how much a file would gain from mangling before you configure a pipeline, or seeing how aggressive terser's compressor gets on a function you're curious about.
For the stylesheet that goes with it, CSS Minifier uses a context-aware scanner instead of a parser. That's enough for CSS, but nowhere near enough for JavaScript. If you want a configuration blob compacted instead, the Minify mode in JSON Formatter reports byte savings the same way.
Your source is never uploaded. Terser runs in your tab, the editor draft is kept in sessionStorage for this tab only, and the "Clear it now" link removes it straight away.
Frequently asked
Does it rename my variables?
Yes. Terser runs with mangling enabled, so local identifiers are shortened to single letters within their own scope while anything you export keeps its name. That is where most of the size reduction comes from, and typical application code ends up 40 to 60 per cent smaller.
What happens if my code has a syntax error?
Nothing is minified and you get the line and column where the parser gave up. That location is where the problem became unavoidable, which is often a line or two after the missing brace that caused it, so read upward from there.
Is the output safe to ship?
The transformation is a real compiler pass, so it preserves behaviour where the input is valid. No source map is produced here, though, so the result is not something you would want to debug in a browser — a build step with esbuild, SWC or terser itself is the right place for production output.
Why can a minifier not just be a few regular expressions?
Because it cannot tell code from text. The previous version truncated any line where a URL string contained a double slash, destroyed regex literals, rewrote multi-line template literals, and broke automatic semicolon insertion — all silently, with the failures surfacing later at runtime.