HandyBench

JavaScript Minifier

Shrink JavaScript with real AST-based minification.

How to use the JavaScript Minifier

  1. 1 Paste your JavaScript into the editor.
  2. 2 Toggle mangle (shorten variable names) and compress (remove dead code) as needed.
  3. 3 Click Minify and copy or download the result, along with the bytes saved.

What Terser does to your code

This page runs Terser (version 5), the minifier behind webpack, Vite and many other build tools. Unlike a whitespace stripper, Terser parses your code into an abstract syntax tree, transforms the tree, and prints it again in the shortest form it can find. The page exposes two switches, which map to Terser's mangle and compress options; every other option stays at its default.

SwitchWhat it does
Always onWhitespace and line breaks go, semicolons and braces are dropped where optional, string quotes switch to the shorter style, and comments are removed except those beginning with /*! or containing @license or @preserve.
MangleRenames local variables and function parameters to one or two letters.
CompressRewrites code to be smaller: removes unreachable branches such as if (false), inlines variables that are used once, and folds constants.

Worked example

This 152-byte function:

function greet(name) {
  const message = 'Hello, ' + name + '!';
  if (false) { console.log('never'); }
  return message;
}
console.log(greet('world'));

gives these results with each setting.

MangleCompressBytesOutput
onon68function greet(e){return"Hello, "+e+"!"}console.log(greet("world"));
offon74Same, but the parameter is still called name
onoff110Keeps the message variable (renamed to o) and the dead if (false) block
offoff128Whitespace stripped only

With both options on, that is a 55% saving.

What it will not do

  • Top-level names are not mangled or removed. The default Terser setting treats top-level variables as possibly used by other scripts, so a global var top or an unused const unused = 1 in the pasted code both survive. Wrap your code in a function or module if you want those names shortened.
  • Property names are never renamed. obj.longPropertyName stays as written, which keeps output safe for code that reads properties from JSON.
  • No source map is produced. The page outputs only the minified code, so debugging in production will show mangled names. Keep your original file.
  • Modern syntax is accepted. Terser reads current ECMAScript syntax, but it does not transpile it, so arrow functions and optional chaining stay as written.
  • Comments with a licence tag are kept on purpose. Add /*! ... */ if your licence requires an attribution line to ship.

Errors

If the code does not parse, nothing is output and the Terser message is shown, for example "Name expected" for let = ;. The message is shown on its own, without a line number. Fix the syntax, then try again.

The Input and Output figures are measured in bytes, and the saving does not account for gzip or Brotli on the server. For the stylesheet and markup side of the same job, use the CSS minifier and HTML minifier.

Examples

  • ▸ Shrinking a 40 KB bundle before deploying to production.
  • ▸ Minifying a small script to paste inline in HTML.

Frequently asked questions

How is this different from a find-and-replace whitespace stripper?

It uses Terser, a real JavaScript parser and AST-based minifier — the same engine used by major build tools. That means it safely renames local variables, drops dead code and removes whitespace without breaking your syntax, unlike naive regex-based minifiers.

What does "mangle" do?

Mangle renames local variables and function parameters to short one- or two-letter names, which shrinks the file further. Disable it if you need to keep readable names for debugging.

What does "compress" do?

Compress applies dead-code elimination and expression simplification (folding constants, dropping unreachable code, shortening conditionals) before the output is printed.

Is my code uploaded anywhere?

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

What happens if my JavaScript has a syntax error?

Terser's parse error message is shown, for example "Name expected", and nothing is minified until the code parses successfully. The message appears without a line number, so use your editor or a linter to locate the problem.

Does it produce a source map or rename top-level variables?

No source map is produced, so keep your original file for debugging. Top-level (global) names are not mangled or removed, because Terser assumes other scripts may use them; wrap code in a function or module to have its names shortened.