Skip to content
koducathome

JavaScript Minifier

Minify modern JavaScript with Terser — compress, mangle names and see the size reduction.

How to use this tool

Steps for using the JavaScript Minifier.

  1. Paste JavaScript into the Input JavaScript panel, click Upload .js to open a file (read locally, never uploaded), or click Sample.
  2. Choose Minify to shrink the code or Beautify to make minified code readable again. Ctrl/⌘ + Enter runs the current action.
  3. Set the options: Target ECMAScript version, Compress, Mangle names, Keep fn/class names (for code that relies on fn.name), Top-level (also rename top-level names in bundles), Drop console, Keep license comments, ES module for import/export, and Source map. The output updates when you change an option.
  4. Read the status bar: original and minified size, gzip size before and after, and how long it took. Syntax errors show the line and column — click Go to line to jump there.
  5. Copy the result, Download it as name.min.js (plus the .map file when source maps are on), or Expand it to full screen. Test the minified file before deploying.

Example

Minify an ES module

Input JavaScript (ES module on)
// Debounce: run fn only after calls stop for wait ms
export function debounce(fn, wait = 200) {
  let timer;
  return (...args) => {
    clearTimeout(timer);
    timer = setTimeout(() => fn(...args), wait);
  };
}
Minified JavaScript
export function debounce(e,t=200){let o;return(...u)=>{clearTimeout(o),o=setTimeout(()=>e(...u),t)}}

Common use cases

  • Minifying a standalone script or bookmarklet for a site without a bundler.
  • Estimating how much a library would shrink in a production build.
  • Producing a compact snippet to embed in an HTML page or third-party tag manager.
  • Checking that a file parses as valid modern JavaScript — Terser reports the exact location of syntax errors.
  • Comparing the effect of compression and mangling on the same code.

How JavaScript minification works

The tool runs Terser, the minifier used by webpack, Vite and many other build tools. Terser parses your code into a syntax tree and prints it back without comments and unnecessary whitespace. That step alone typically saves a large share of the size of well-commented code, and it is the only step taken when you turn both Compress and Mangle names off.

Compress rewrites code into shorter equivalent forms: it joins consecutive statements with commas, turns if/return pairs into ternaries, folds constant expressions, drops unreachable code and inlines simple values (two passes are run). Mangle names renames local variables and function parameters to one or two letters. Top-level names are only mangled in ES module mode, because in a classic script they are globals that other scripts may reference; exported names and object properties are never renamed.

The ECMAScript version tells Terser which syntax it may use in its own output when it rewrites code — a higher version unlocks transformations that produce newer syntax. Terser does not transpile: modern syntax in your input stays modern, and choosing ES2015 does not convert it for old browsers. Use Babel, esbuild or SWC for that. Likewise, TypeScript and JSX are not JavaScript and are rejected as syntax errors; compile them first.

Minification can change behaviour in edge cases: code that reads Function.prototype.name or class names, relies on eval or with, or depends on side effects that Terser considers removable. Always run your tests or try the page with the minified file before shipping it. License comments (/*!, @license, @preserve) are kept by default so third-party notices survive.

Limitations

  • Does not transpile: TypeScript, JSX and Flow are rejected, and modern syntax is not converted for older browsers.
  • No bundling or tree-shaking across files — each input is minified on its own.
  • Code that depends on function/class names or eval can break when names are mangled; test the output.
  • Input is limited to 2 million characters; very large files may take a few seconds.

Frequently asked questions

Why do I get a syntax error for import/export?

import and export are only valid in ES modules. Turn on ES module and minify again.

Can I minify TypeScript or JSX?

No. Terser only accepts JavaScript. Compile with tsc, esbuild, SWC or Babel first, then minify the JavaScript output.

Why are my top-level function names not shortened?

In a classic script, top-level names are global and other scripts might use them, so Terser keeps them. Turn on ES module if the file is a module — then top-level names that are not exported are mangled too.

Is the minified code guaranteed to work?

Terser is mature and widely used, but no minifier can see how other code uses yours. Test the minified file before deploying it.

Is my code uploaded?

No. Terser runs in your browser; your source never leaves your device.