Home/Dev Tools/JavaScript Minifier

JavaScript Minifier

Minify

Minify JavaScript for production. Compress variables and remove dead code with Terser.

Options
Input
Loading editor…
Output
Loading editor…
✨ AI Code Explanation
Mode

What Is JavaScript Minification?

JavaScript minification is the process of removing all unnecessary characters from source code without changing its functionality — whitespace, comments, long variable names — to reduce the file size that browsers must download. This tool uses Terser, the same minifier used internally by Webpack, Vite, and esbuild, running entirely in your browser.

Before and After Minification

// Before (readable source)
function greet(name) {
  const message = "Hello, " + name + "!";
  console.log(message);
  return message;
}

// After (Terser minified + mangled)
function greet(e){const o="Hello, "+e+"!";return console.log(o),o}

How to Minify JavaScript Online

  1. Paste your JavaScript source code into the left editor pane (or click Load Sample).
  2. Choose your options: Mangle names, Drop console, Keep comments.
  3. Click Minify — the compressed output appears in the right pane.
  4. The stats badge shows original size, minified size, and percentage saved.
  5. Click Copy to copy the output, or Download to save as minified.js.
  6. Use Explain with AI to get a plain-English description of what the original code does.

Minification Options Explained

  • Mangle names (default: on) — renames local variables and functions to single-character names. Significantly reduces file size. Safe for any self-contained script; disable if your code relies on Function.name or runtime reflection.
  • Drop console (default: off) — removes all console.log(), console.error(), and other console calls. Use this for production builds where debug logging is not needed.
  • Keep comments (default: off) — preserves comments in the output. Useful when you need to retain license headers or copyright notices (e.g. /*! MIT License */).

How Much Can Minification Save?

Typical JavaScript files shrink by 40–70% with Terser. A 100 KB script often becomes 30–50 KB. Combined with gzip compression on your server, you can expect an additional 60–80% reduction on top of minification. Most production bundles use both.

Common Minification Errors

  • SyntaxError: Unexpected token — your input has a syntax error. Fix the source first, then minify.
  • Output breaks at runtime — if your code uses eval() with variable names, mangling can break it. Disable Mangle names.
  • Minified code is larger than input — your input was already minified or is very short. The stats badge will show 0% saved.
  • TypeScript syntax in JS file — Terser handles modern JS but not TypeScript type annotations. Use the TypeScript Minifier for .ts files.

Related Tools

Is My Code Sent to a Server?

No — all minification runs entirely in your browser using Terser's browser build. Your code never leaves your machine. No account required, no rate limits on minification.