Allin1Tool
Developer ToolsRuns in your browser

JS Minifier

Minify JavaScript with terser: real parsing, compression and name mangling, ES6 and modules, with parse errors located precisely.

Share:

JS Minifier workspace

Source Editor

Input

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

  1. Paste your JavaScript into the editor, or press Load example to try it on a sample module.

  2. Press Minify JavaScript, which loads terser on demand and parses your source.

  3. If a parse error appears, fix the reported line and column and run it again.

  4. 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 is loaded on demand at the moment you press the button, so nobody who never touches this tool downloads it.

What terser does to your code

Three things, in order. It parses the source into an abstract syntax tree, so from that point on it is reasoning about statements and expressions rather than text. It compresses — dead code after a return is dropped, if (true) branches are folded, constants are propagated, sequences of statements are merged into expressions. And 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 supported in full: 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 lands somewhere between 40% and 60% smaller, with mangling contributing more of that than whitespace removal does.

The reason a parser is not optional

Before the rebuild this page was three regular expressions. Every one of the following is a thing it actually did:

const u = "https://example.com/api";   ->  const u = "https:
const re = /a\/\/b/;                   ->  regex literal destroyed
const t = `line one
line two`;                             ->  template literal rewritten

The first is the classic: // inside a string is not a comment, but a pattern that hunts for // cannot know that, so the rest of the line was deleted. The second is the same mistake inside a regex literal. The third mangled a multi-line template, where every newline is significant.

There was a fourth failure that produced no visible damage until runtime. Removing newlines between statements breaks automatic semicolon insertion — code relying on ASI stops meaning what it meant, and the resulting error surfaces somewhere unrelated. Meanwhile this page claimed lexical parsing, AST traversal and worker-based processing, none of which existed.

Minification is a compiler problem. Anything that is not a parser will eventually corrupt code that is perfectly valid, and it will do so silently.

When the parse fails

Terser will not minify what it cannot parse, and neither will it guess. A syntax error is reported with the line and column where the parser gave up. That location is where the parser noticed the problem, which is often a line or two after the missing brace or stray comma that caused it — read upward from there.

This makes the tool a passable syntax check. If your file minifies, it parses.

Where this fits, and where it does not

Minification runs on the main thread. For a component, a utility module or a snippet you are about to inline, that is imperceptible. For a bundle of several megabytes it is the wrong venue entirely, and not because of 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 the output is not something you would want to debug in a browser.

The realistic uses are one-off: shrinking a snippet for a CMS field, checking how much a file would gain from mangling before you configure a pipeline, or inspecting how aggressive terser's compressor gets on a function you are curious about.

For the stylesheet alongside it, CSS Minifier uses a context-aware scanner rather than a parser, which is enough for CSS and not remotely enough here. For a configuration blob you want compacted instead, the Minify mode in JSON Formatter reports byte savings the same way.

Your source is never uploaded. Terser executes in your tab, the editor draft is confined to sessionStorage for this tab, and the "Clear it now" link removes it at once.

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.