3tej home

What is JavaScript Minifier?

A JavaScript Minifier reformats your input for readability without changing its meaning. It parses the source, applies consistent indentation, spacing and casing, and returns a clean copy you can paste back into your project. Strip whitespace, mangle variable names, compress.

JavaScript Minifier

Minify and mangle JavaScript in your browser. Powered by Terser; typical 50-70% size reduction.

🔒 Browser-only ⚡ Instant 💸 Free forever 📡 Works offline 🚫 No signup
← Utilities

TLDR

Paste JavaScript and click Run. The page uses Terser (the industry-standard JS minifier used by webpack, Vite, and Parcel) to strip whitespace, rename variables, and compress expressions. Typical savings: 50-70% on un-minified code.

Runs entirely in your browser. No upload, no signup, no logging. Output is for personal or commercial use; we don't claim any rights.

About this JavaScript minifier

A JavaScript minifier rewrites a script as a semantically equivalent but byte-smaller version. The output runs identically in every engine, but it is faster to download, faster to parse, and smaller after gzip or brotli compression. This page runs Terser, the de facto standard minifier maintained by the original UglifyJS author. Terser powers the production builds of Webpack, Vite, Rollup, esbuild (when feeding Terser as the final pass), Parcel, and roughly every JavaScript bundler shipped after 2018.

Three transformations do most of the work. Whitespace and comments collapse, identifiers shorten (local variables become single letters in a process called mangling), and dead code is eliminated (an if (false) { ... } branch is removed entirely). On a typical React component, Terser cuts source size by 30 to 55 percent before gzip, then gzip squeezes the renamed identifiers another 20 to 30 percent because mangled names repeat predictably.

How the minifier works

The page loads Terser from a public CDN and runs it locally on your code. Your script is never uploaded.

const result = await Terser.minify(input, {
  compress: { drop_console: false, passes: 1 },
  mangle:   { toplevel: false, reserved: [] },
  format:   { comments: /^!|@preserve|@license/ },
});
console.log(result.code);   // minified output
console.log(result.error);  // syntax error, if any

The pipeline is: parse to AST, run compress passes (constant folding, dead code elimination, expression simplification), mangle (rename locals to one or two characters), then emit. Top-level mangling stays off by default so global exports keep their original names; flip mangle.toplevel on for IIFE-wrapped bundles where nothing escapes.

Worked example: before and after

Input (267 bytes, formatted):

function calculateTotalPrice(basePrice, quantity, discountPercent) {
  const subtotal = basePrice * quantity;
  const discountAmount = subtotal * (discountPercent / 100);
  const finalPrice = subtotal - discountAmount;
  return finalPrice;
}
console.log(calculateTotalPrice(100, 3, 10));

After Terser with default options (94 bytes, one line):

function calculateTotalPrice(o,n,c){const t=o*n;return t-t*(c/100)}console.log(calculateTotalPrice(100,3,10));
65 percent byte reduction before gzip. Parameters renamed to o, n, c; the intermediate discountAmount and finalPrice were folded into a single return expression. Behavior is identical: the call still logs 270.

With compress.passes: 3 Terser would also inline the function entirely if it sees the call exactly once, reducing the output to just console.log(270) at build time.

Minifier options compared

MinifierEngineTypical reductionSpeedNotes
TerserJS (Node + browser)30 to 55 percentSlow (single threaded)Best compression; default in Webpack 5 and Vite.
SWC minifyRust28 to 50 percent~7x faster than TerserDrop-in inside Next.js 12 and later; near-Terser quality.
esbuild minifyGo20 to 40 percent~50x faster than TerserSingle-pass; trades a few percent compression for build speed.
UglifyJS 3JS25 to 45 percentSlowOlder, no ES2017+ syntax; superseded by Terser.
Closure Compiler (advanced)Java40 to 70 percentVery slowMost aggressive (whole-program dead code); requires type hints.
This pageTerser via CDN30 to 55 percentBrowser-onlyFree, zero install; for ad-hoc minification.

Common pitfalls

  • Minifying code that uses Function.prototype.name for routing. Mangling renames functions, so frameworks that introspect fn.name break in production. Add reserved names to mangle.reserved or disable top-level mangling.
  • Stripping console.log on a debug page. If you enable compress.drop_console: true in a debug build, you lose the diagnostic output you wanted to read. Wire the flag to NODE_ENV === 'production'.
  • Forgetting /*! @license */ comments. Terser drops every comment by default. Open-source licenses must travel with the code, so mark them with /*! or use the format.comments regex shown above.
  • Minifying ES modules then loading them via classic script. Terser preserves import and export by default. If your runtime expects a UMD or IIFE wrapper, run a bundler first; the minifier alone will not produce a script-tag-loadable file.
  • Expecting source maps from this page. The browser tool returns minified code only. Production builds need sourceMap: { url: 'inline' } or an external map, which requires the bundler integration so the map can be served alongside.
  • Running Terser on already-minified vendor code. Each pass is destructive; re-mangling can occasionally rename a reserved identifier the original author depended on. Treat bundled vendor files as black boxes and concatenate, not re-minify.

Related developer tools

Frequently asked questions

Is this javascript minifier free?

Yes - free forever, no signup, no daily limit. Everything runs in your browser.

Where does my code go?

Nowhere. The transform runs entirely in your browser. Nothing is uploaded, stored, or logged.

Does it work offline?

After first load, yes. The CDN-loaded libraries cache in your browser and the page works without a connection.

Is the output exactly the same as my IDE?

Very close - the library is the same one most IDEs use under the hood (js-beautify for HTML/CSS/JS; Terser for JS minification; js-yaml for YAML). Spacing and line-break choices may differ by a few characters versus Prettier.

Will it handle very large files?

Yes up to several megabytes. For 10+ MB inputs the browser may freeze briefly during processing.

Will the minified output break in older browsers?

Minifiers do not introduce new syntax - they just shorten what is already there. If the input ran on Internet Explorer 11, the minified version still does. For modern ES2022+ syntax check your Babel/SWC config separately.

Does the formatter / minifier preserve comments?

Formatter: yes by default. Minifier: depends. Terser drops all comments unless they look like /*! ... */ legal headers. CSS / HTML minifiers strip all comments unless preceded by `!`.

Can I run this on a whole codebase?

Not in one click - this tool processes one file at a time. For a whole codebase use prettier --write . / eslint --fix / terser --compress in your CI. This tool is for quick one-off paste-and-format.

Is the source map preserved when minifying?

No - the tool minifies in place and returns just the minified code. For production builds that need source maps, run Terser in your bundler (Webpack/Vite/esbuild) where the source-map pipeline is wired in.

How does this compare to Prettier?

Prettier is opinionated and reformats more aggressively (line length, trailing commas, quote style). js-beautify is conservative - it preserves most stylistic choices and just fixes indentation + whitespace. Use Prettier for team-wide style consistency; use this for ad-hoc inspection.