Tools

JavaScript minifier

Minify JavaScript with terser — compression, name mangling, an ECMAScript target — and see the size before and after gzip.

Runs in your browserCode converters9.3K
Free

Input

0 B

Result

The result will appear here.

terser is the minifier webpack runs by default in production mode, and the one Vite and Rollup offer when you want the smallest output. Paste a script to have it compressed the same way: dead code and redundant expressions removed, local names shortened, whitespace stripped. The result shows the saving in bytes and, where the browser supports CompressionStream, the gzipped size before and after — the number that actually travels over the network.

How it works

  • Compress rewrites the code in two passes — inlining constants, dropping unreachable branches, folding expressions — and mangle shortens local variable and parameter names.
  • Top-level names are left alone unless you mark the input as an ES module, because a classic script's globals may be used by other scripts on the page.
  • Comments that start with /*! or contain @license or @preserve are kept, as most licences require.
  • The ECMAScript version controls what terser may emit — ES5 never gains arrow functions — but newer syntax you wrote yourself is not transpiled down.

Where your data goes

Nowhere. This tool runs entirely in your browser: the text you paste is processed by the page and is never transmitted to a server or written to a log.

This tool is free and needs no account. Its results exist only in your open page and are not saved anywhere.

What it costs

This tool is free, with no sign-in and no points.

Common questions

Why is the gzipped saving smaller than the raw one?
Because gzip already removes much of the same redundancy: repeated whitespace and long, repeated identifiers compress very well. A large raw saving therefore shrinks once both sides are gzipped. That smaller figure is still real, and it is the one to use when estimating transfer size.
Can minification break my code?
terser's default transformations are designed to be safe for standard JavaScript. What breaks is code that depends on function or class names at runtime (Function.prototype.name, some dependency-injection setups) or reads its own source through toString(). Switch mangling off to confirm whether names are the problem.
What does dropping console calls do?
It removes console.log, console.warn and every other console.* call from the compressed output. Handy for a production bundle; harmful if you rely on console.error to report failures from users' browsers. It only applies when compression is on.
Can it minify TypeScript or JSX?
No, terser reads JavaScript only and will report the first type annotation or JSX tag as a syntax error. Compile TypeScript and JSX first with tsc, esbuild or Babel, then minify the JavaScript they produce.

The open-source behind it

This tool runs on terser/terser, released under BSD-2-Clause. If you need the same behaviour inside your own program, that is the library to reach for.

terser/terser

Also known as

  • javascript minifier
  • js minify online
  • terser online
  • minify js
  • compress javascript
  • uglify js