Skip to content
Devtoolry

JavaScript Minifier

Minify and mangle JavaScript online with Terser for smaller bundles. Supports modern ES syntax, with compress and mangle options and the size saved.

Runs in your browser · Nothing uploaded · No sign-up

Something not working, or missing a feature? Send feedback

About the JavaScript Minifier

The JavaScript Minifier uses Terser, the minifier behind most JavaScript bundlers, to remove whitespace and shorten local variable names (mangling) for smaller files.

Everything runs in your browser, so your input is never uploaded to a server.

How to use the JavaScript Minifier

  1. Paste JavaScript or open a file.
  2. Choose whether to mangle names and apply compression optimisations.
  3. Copy or download the minified code.

Example

Minify a small function

Input

export function calculateTotal(items, taxRate) {
  // Sum the line totals, then add tax
  const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
  const tax = subtotal * taxRate;
  return Math.round((subtotal + tax) * 100) / 100;
}

Result

export function calculateTotal(t,c){const e=t.reduce((t,c)=>t+c.price*c.quantity,0),n=e*c;return Math.round(100*(e+n))/100}

The comment is removed, local names are shortened and the two constants are merged into one declaration. The exported name calculateTotal is kept, so other modules can still import it.

Common mistakes

  • Code that relies on function names. Mangling renames local functions and classes, so code that reads fn.name or constructor.name gets different values. Switch off mangling for such code.
  • Shipping without a source map. Errors in minified code point to line 1 and short names. Keep the original file, or build with a bundler that writes source maps, for debugging.
  • Top-level code disappears. Code is minified as an ES module, so top-level functions and variables that are never used or exported are removed. Export what other files need, or call it, and it is kept.
  • Minifying JSON or TypeScript. The input must be JavaScript. Compile TypeScript first, and use the JSON Minifier for JSON.

Works well with the JavaScript Minifier

Frequently asked questions

What does mangling do?

It renames local variables and function parameters to short names. Global names and object properties are left alone, so behaviour does not change.

Does it support modern syntax?

Yes, ES2015+ features such as modules, classes, async functions and optional chaining are supported.

Is it as small as my bundler’s output?

It uses Terser, which most bundlers use, so a single file comes out the same. Bundlers also remove unused exports across files, which a single-file minifier cannot do.

Is my code uploaded?

No. Terser runs in your browser, so the code never leaves your device.