JavaScript Minifier

Paste JavaScript to shrink it with Terser: dead code is removed, names are shortened and whitespace disappears. Syntax errors point to the exact line and column.

Runs in your browserNo sign-upNothing uploaded

Minified output

How to use the JavaScript Minifier

  1. Paste your JavaScript or open a .js file.
  2. Choose options: Mangle names shortens local variables, Compress rewrites code into a smaller equivalent, ES module enables top-level import/export.
  3. Pick the ECMAScript target your users' browsers support. ES2020 is safe for all evergreen browsers.
  4. Check the size, savings and gzip estimate under the output.
  5. Copy the minified code or download it as output.min.js.

What does a JavaScript minifier do?

Minification makes JavaScript smaller without changing what it does. This tool uses Terser, the minifier behind webpack, Vite and Rollup, and applies three kinds of changes:

  • Whitespace and comment removal: indentation, newlines and comments are not needed by the JavaScript engine.
  • Mangling: local variable and function parameter names such as subtotal become single letters. Global names and object properties are left untouched so your public API keeps working.
  • Compression: constant expressions are folded, unreachable code is dropped, if statements become ternaries and short functions are inlined.

Minify vs. gzip: do you need both?

Yes. Gzip and Brotli compress repeated byte patterns on the wire, while minification removes bytes the browser would otherwise have to download, parse and compile. A typical script shrinks 40–60% from minification and then another 60–70% from gzip. The gzip size shown here is a good estimate of what your server will actually send.

Keeping license comments

Many open-source licenses (MIT, BSD, Apache) require the copyright notice to stay with the code. By convention, comments that start with /*! or contain @license or @preserve are kept when Keep license comments is on.

When not to minify by hand

If your project already uses a bundler, let it minify production builds and generate source maps for debugging. An online minifier is ideal for one-off scripts, snippets for a CMS or tag manager, bookmarklets and checking how small a piece of code can get.

Frequently asked questions

Is my code uploaded to a server?
No. Terser runs inside your browser tab, so proprietary code never leaves your machine.
Can minification break my code?
Terser only applies transformations that keep behaviour identical for valid JavaScript. Code that relies on Function.prototype.toString() or on local variable names through eval can be affected; turn off Mangle names in that case.
Does it support modern syntax such as async/await, classes and optional chaining?
Yes. Terser parses ES2022+ syntax. The target setting only controls which syntax the output may use; it does not transpile newer features down to older ones.
What is the difference between minify and uglify?
They mean the same thing. UglifyJS was the classic tool; Terser is its maintained fork with full ES2015+ support.

Related tools