Quick answer: minification removes what browsers don't need — comments, whitespace, and (with mangling) long variable names — without changing what the code does. Percent saved = (input − output) ÷ input × 100. On our 823-byte cart-totals sample, Terser strips it to 651 B (20.9% saved), compresses to 598 B (27.3%), and compress+mangle reaches 390 B (52.6% saved, 277 B gzipped). All three passes compute the identical $74.68 cart total. Everything runs locally; no code is uploaded.

Your JavaScript

Input
Output
Saved
Gzip in → out
Advertisement

What Each Terser Pass Buys You

PassWhat it removes823-B sample →Saved
Strip onlyComments, indentation, newlines651 B172 B (20.9%)
Compress…plus dead branches, constant folding, joined declarations598 B225 B (27.3%)
Compress + mangle…plus 1–2 character names, inline helpers (TAX_RATEt)390 B433 B (52.6%)
Same file, gzippedTransport compression on top of the smallest pass277 B29.5% off the 393-B gzip

Every row was measured with Terser 5.51.2 — the exact browser bundle this page loads — on the sample behind the Sample button. Your mileage depends on your comment density and name lengths: a heavily commented file shrinks more; a machine-generated bundle shrinks less.

How the JS Minifier Works

This tool is a thin, honest wrapper around Terser 5.51.2 (BSD-2-Clause), the minifier that webpack, Vite, and Parcel lean on in production builds. It loads the official Terser browser bundle on first use and runs it in your tab. No server sees your code, which makes it usable for quick one-off shrinks, snippets heading into CMS blocks, or checking what a bundler pass would buy you.

The math

Bytes saved = input − output. Savings percent = (input − output) ÷ input × 100. The tool counts UTF-8 bytes (not characters) so multi-byte strings report honestly, and when your browser supports CompressionStream it also shows gzip sizes for both sides — the number that actually crosses the network.

How to use it

Paste code (or hit Sample), pick a preset, and results update as you type. Strip only is the safe default for code you'll still need to debug from stack traces: line breaks go but nothing is renamed. Compress rewrites the logic to shorter equivalents. Compress + mangle also renames top-level names — smallest output, but other scripts can no longer call your globals by name, and Function.prototype.name changes.

A worked example

The Sample button loads an 823-byte cart-totals script: a tax constant, a money formatter, a per-line discount helper, and a cartTotal() that returns subtotal, tax, and total. Run each preset and the output column walks down 651 → 598 → 390 bytes. We verified all three outputs in Node against the same bundle: each one computes {subtotal: "$68.99", tax: "$5.69", total: "$74.68", itemCount: 2} from a two-item cart — identical answers, 52.6% of the bytes gone at the strongest pass, and 277 B once gzipped.

One caution worth repeating: minification is not obfuscation. Anyone can pretty-print 390 bytes back to readable form in seconds. If the goal is deterring reverse engineering rather than shipping smaller files, that's a different tool — our JS Obfuscator lane covers it.

Frequently Asked Questions

Is minified JavaScript still valid JavaScript?

Yes. Terser parses your code into an AST and prints it back out, so the output is syntactically valid by construction. Semantics can shift only for code that relies on function and variable names at runtime — Function.prototype.name, recursion by name after top-level mangling, or eval-based lookups. We verified all three passes on a cart-totals sample: every version computed the identical $68.99 subtotal, $5.69 tax, and $74.68 total.

How much smaller will my JavaScript get?

It depends on how much of the file is comments, whitespace, and renamable identifiers. On our commented 823-byte sample, stripping alone saved 20.9%, compression brought it to 27.3%, and compression plus mangling reached 52.6%. Real bundles — already terse, with long shared strings — usually land between 30% and 50% raw, and less after gzip because renames compress well anyway.

What does mangle actually rename?

Mangling shortens identifiers to 1-2 characters. It's scope-aware by default: a variable inside a function is renamed without touching same-named variables elsewhere. Top-level mangling (toplevel: true, used by the smallest preset here) also renames globals in the file, which is safe for self-contained scripts and bundles but breaks code that expects those names from outside — drop it if other scripts call into yours by name.

Does minification replace gzip or Brotli?

No, they stack. Minification shrinks the file; transport compression shrinks it further on the wire. Our sample goes 823 to 390 bytes minified, then gzips down to 277 — and the tool shows both columns so you can see the real over-the-wire size. Serve minified files with gzip or Brotli enabled; never rely on transport compression alone to undo wasteful source.

Is my code uploaded anywhere?

No. Terser 5.51.2 is loaded from a CDN into your browser and runs locally, like the rest of ToolAspect. Your JavaScript never leaves the tab — which is why this tool is usable on proprietary code, though you should still follow your employer's policy on pasting source into third-party pages.

Why does the tool show an error on my code?

Terser refuses to minify code it cannot parse, so the error usually means a syntax error — a missing brace or bracket — or non-standard syntax the parser doesn't accept. The status line surfaces Terser's own message with a line reference. Fix the syntax and it re-runs automatically as you type.

Advertisement