ToolLaunchpad
Developer tools

JavaScript Minifier

Paste JavaScript to shrink it with Terser, the minifier used by most modern build tools. Choose compression, name mangling and comment handling, and see exactly how many bytes you save.

JavaScript MinifierRuns in your browserCtrl+Enter runs

  • 0 BOriginal
  • -Minified
  • -Saved
  • -Minified + gzip

Runs entirely in your browser. Nothing you enter is uploaded or stored.

How to use the JavaScript minifier

  1. Paste your script into the input box and press Minify (or Ctrl+Enter).
  2. Leave Compress and Mangle names on for the smallest output. Turn them off if you only want whitespace and comments removed.
  3. Keep license comments preserves comments that start with /*! or contain @license or @preserve. Untick it to drop every comment.
  4. Tick ES module for code that uses import or export. Module code is strict and its top-level names are private, so Terser may rename and remove them.
  5. Check the size tiles, then copy the result or download it as a .min.js file.

The minifier is Terser, the same engine used by webpack, Vite and Rollup, loaded from this site and running in your browser. Your code is not uploaded.

Worked example

Input:

/*! demo v1 */
function add(first, second) {
  // sum two numbers
  const result = first + second;
  return result;
}
console.log(add(2, 3));

Output with the default options:

/*! demo v1 */
function add(d,n){return d+n}console.log(add(2,3));

The ordinary comment is gone, the temporary variable is inlined and the parameters are renamed. The function name add stays, because in a classic script a top-level function is a global that other scripts might call. With ES module ticked and comments off, Terser knows nothing outside can see add, inlines it and the whole program becomes console.log(5);.

Compress, mangle and gzip

Compression rewrites code into shorter equivalent code: it drops unreachable branches, folds constant expressions, joins variable declarations and turns if statements into && or ternaries. Here it runs two passes. Mangling renames local variables and parameters to one or two letters, which usually saves the most bytes. Property names are never mangled, because that breaks code that accesses objects by string.

Sizes are counted in UTF-8 bytes. The gzip tile compresses the minified code with your browser's built-in CompressionStream, which is close to what a web server sends when compression is enabled. Gzip already removes much of the repetition, so the saving over the network is smaller than the raw percentage suggests, but the browser still has less code to parse.

Common mistakes

  • Syntax errors – Terser parses the whole file first. The status line shows the line and column of the first error; TypeScript and JSX must be compiled to JavaScript before minifying.
  • Expecting transpilation – Terser keeps modern syntax such as arrow functions, classes and const. It makes code smaller, not compatible with older browsers; use a transpiler such as Babel for that.
  • Code that reads function names – code that relies on fn.name or class.name can change behaviour after mangling. Turn mangling off for such code.
  • Missing license notice – many open-source licenses require the notice to stay. Write it as /*! ... */ so it survives.

Minifying stylesheets too? Use the CSS minifier. To embed the minified script in a data URL, encode it with the Base64 encoder.

Frequently asked questions

Is my code uploaded anywhere?

No. Terser runs as JavaScript in your browser tab. The code you paste is never sent to a server, which makes the tool safe for private or unreleased source code.

Will minified code behave exactly like the original?

For standard code, yes: Terser only applies transformations that keep the behaviour. Code that depends on function names, on eval, or on exact toString output can be affected by mangling, so turn mangling off for such code.

What does the ES module option do?

It treats the input as an ES module: strict mode applies and top-level names are private to the module instead of global. Terser can then rename, inline or remove unused top-level functions and variables.

Which comments are kept?

With Keep license comments on, comments starting with /*! or containing @license or @preserve are kept. All other comments are removed. Turn the option off to remove every comment.

Why is the gzip size so much smaller?

Gzip finds repeated sequences such as keywords and property names and stores them once. Web servers usually send JavaScript gzip- or Brotli-compressed, so the gzip figure is close to what visitors actually download.

Can it minify TypeScript or JSX?

No. Terser understands standard JavaScript only. Compile TypeScript or JSX first, for example with tsc or esbuild, then minify the generated JavaScript.

More free Launchpad tools