DT Dev Tools

JavaScript Minifier

Minify JavaScript with Terser in your browser: compress, mangle names, drop console calls and compare file sizes before and after.

🔒 Runs entirely in your browser — nothing is uploaded

Drop a .js file here or click to browse — or paste code below

Before: –After: –Saved: –
Advertisement

How JavaScript minification works

Minification makes JavaScript smaller without changing what it does. This tool uses Terser, a mature minifier that parses your code into an abstract syntax tree, transforms it, and prints it back without unnecessary whitespace and comments. The compress step applies dozens of optimizations: it removes unreachable code and unused variables, inlines constants, joins consecutive variable declarations, turns if statements into shorter conditional expressions where possible and evaluates simple constant expressions at build time. The mangle step then renames local variables, parameters and function names to one or two letters. Property names and globals are left alone, so the public behavior of your code stays the same.

The size badges show the UTF-8 byte size of the input and output and the percentage saved. Typical hand-written code shrinks by 40–70%; code that is already compact or dominated by long strings will shrink less. Remember that servers usually compress JavaScript again with gzip or Brotli, so the real transfer saving is smaller than the raw number, but minified code still parses faster and costs less bandwidth.

Choosing the right options

The ECMAScript target tells Terser which syntax it may use in the output. With ES2020 it can emit arrow functions, optional chaining and other modern forms; with ES5 it avoids introducing newer syntax, although it does not transpile modern code you wrote — use a tool like Babel or esbuild for that. Keep console.* preserves logging, which is useful for staging builds. Enable ES module for files that use import/export; it also allows top-level names to be mangled because module scope is private.

Private by design

The minifier is loaded on demand and runs locally, so your source code is never uploaded. That makes it suitable for quick one-off tasks such as shrinking an inline script, a bookmarklet or a snippet for a third-party tag manager. If Terser reports a syntax error, the message includes the line and column so you can fix the input. For production bundles, keep minification in your build pipeline so it is repeatable, and generate source maps for debugging.

How to use

  1. Add your codePaste JavaScript into the input or drop a .js file onto the drop zone.
  2. Choose optionsToggle compression, name mangling, console removal, module mode and the ECMAScript target.
  3. MinifyClick Minify JavaScript to see the output with the size before, after and the percentage saved.
  4. Copy or downloadCopy the minified code or download it as a .min.js file.

Frequently asked questions

Which minifier does this use?
Terser, the default JavaScript minifier in webpack and an optional minifier in Vite and Rollup. It runs entirely in your browser.
What is the difference between compress and mangle?
Compress rewrites code into a shorter equivalent form — removing dead code, folding constants and simplifying expressions. Mangle renames local variables and function parameters to short names. Both are safe for normal code and can be toggled independently.
Why did my console.log calls disappear?
By default the compressor drops console.* calls, which is common for production bundles. Tick Keep console.* to preserve them.
When should I enable ES module?
Enable it if your file uses import or export statements. Module mode also lets Terser mangle top-level names, which is safe for modules but can break classic scripts that expose globals.
Advertisement