JavaScript Minifier

: Minify JavaScript with Terser: compress, mangle names and drop comments in your browser
Limits: 50 MB · .js, .mjs or .cjs · Terser with its safe defaults: no unsafe transforms, no property renaming. JSX and TypeScript are not supported. · To tidy code instead, use Code Formatter
MinifiedClassic script: top-level names stay, since other scripts on the page may use them
Options
Only limits what the minifier may introduce; it never converts newer syntax down
The minified code appears here as you type.

Minify JavaScript with Terser 5, the minifier behind many build pipelines. Paste a script or open a .js file and get back a smaller version with whitespace and comments removed, expressions simplified and local names shortened, with the before and after sizes (raw and gzip) shown next to it.

  1. Paste code into JavaScript, or press Open file to load a .js, .mjs or .cjs file. Example loads a small export class and turns on ES module for you.
  2. Set the options you need. A .mjs file switches ES module on and a .cjs file switches it off. If the code uses import, export or top-level await, turn ES module on.
  3. Input up to 256 KB is minified automatically about 300 ms after you stop typing. Larger input waits until you press Minify, and Cancel stops a run that is in progress.
  4. Read the size line under Minified: bytes before and after with the percentage change, plus the gzip size of each. If the code does not parse, the error names the line, and Go to line puts the cursor there.
  5. Press Copy, or Download to save the result as name.min.js (a pasted script is saved as script.min.js). With Source map on, the Download menu also offers the map as name.min.js.map.

A small classic script with the default options. The license banner is kept, the comment is dropped, the local variables get one-letter names, the loop is merged into one for statement and cartTotal keeps its name because top-level names of a classic script are not renamed.

Input
/*! cart-total 1.0 | MIT */
// Sum the prices in a cart and apply a discount.
function cartTotal(items, discountPercent) {
  var subtotal = 0;
  for (var i = 0; i < items.length; i++) {
    subtotal += items[i].price * items[i].quantity;
  }
  var discount = subtotal * (discountPercent / 100);
  return Math.round((subtotal - discount) * 100) / 100;
}
Output
/*! cart-total 1.0 | MIT */
function cartTotal(r,t){for(var a=0,n=0;n<r.length;n++)a+=r[n].price*r[n].quantity;var o=a*(t/100);return Math.round(100*(a-o))/100}

How do I minify JavaScript online without uploading it?

Paste the code or open the file here and read the result from output. The work is done by Terser in a worker inside your browser tab, so the code never leaves your device.

Does minifying JavaScript break code?

Not with the defaults, which use only Terser's safe transformations, leave top-level names of classic scripts and all property names alone, and do not change what the code does. Problems come from code that depends on function names (use keep function & class names), on eval or code built from strings, or from selecting the wrong ES module setting. Test the minified output like any other build.

What is the difference between minify and gzip?

Minifying rewrites the source into shorter source, which stays valid JavaScript. gzip compresses the bytes for transfer and the browser unpacks them. They stack: the stats line shows both, such as 229 bytes gzipped before and 153 bytes after for the example. Serve minified files with gzip or Brotli enabled for the smallest download.

Why did the file only shrink a little, or grow?

Code that is already minified has nothing left to remove, and the tool warns when the output is not smaller than the input. Tiny files can also gain nothing from renaming. Check that compress and mangle names are on.

Is minified JavaScript the same as obfuscated?

No. Minification aims at size and keeps the logic as it was; it is not a security measure. Pass the output through a formatter and most of the structure comes back, except the original local names and comments.

Runs entirely in your browser. Nothing is uploaded.