WebTools

Minify JavaScript

Terser in the browser, with optional name mangling.

Minify JavaScript with Terser, the same minifier behind most build tools. It strips comments and whitespace, shortens local variable names and simplifies dead code.

It handles modern syntax, including ES modules, optional chaining and private class fields.

How to use it

  1. Paste the code.
  2. Tick whether it is an ES module and choose the target.
  3. Copy or download the .min.js.

Frequently asked questions

Why do I have to say whether it is an ES module?
Because modules are always in strict mode and have their own scope. Told that, Terser can shorten names that in a classic script would be globals and off limits.
Will shortening names break anything?
Local names are safe. What does break is code that reaches them by string, such as a framework injecting dependencies by parameter name.
It reports a syntax error the browser did not.
Terser parses the whole file first. Often it is syntax newer than the chosen target: raise the target to ES2020 and try again.

Related tools