FormatterHQ

JavaScript Minifier

Shrink JavaScript with Terser: whitespace and comments removed, local names shortened, and code compressed. The status bar shows how many bytes you saved.

Input JAVASCRIPT
Output JAVASCRIPT
Ready.

How to use the JavaScript Minifier

  1. Paste your JavaScript into the Input editor, or use Sample, Upload file or Load URL to minify a .js file.
  2. Choose options: Shorten variable names, Compress code and Keep license comments.
  3. Press Minify; the status bar shows the original and minified size and the percentage saved.
  4. Use Copy or Download above the output panel to take the minified script with you.

A JavaScript minifier built on Terser

This JavaScript minifier uses Terser, the minifier inside webpack, Rollup, Vite and many other build tools. It parses your code into a syntax tree, applies optimizations, and prints the smallest equivalent code it can. The result downloads faster and parses sooner in the browser. Smaller scripts matter most on mobile networks, and every kilobyte you save is also saved for each visitor on every uncached visit.

Example

/*! MyLib v1.2 | MIT */
// helper
function calculateTotal(items, taxRate) {
  const subtotal = items.reduce((sum, item) => sum + item.price * item.qty, 0);
  if (taxRate === undefined) {
    return subtotal;
  }
  return subtotal * (1 + taxRate);
}
export { calculateTotal };
function e(e,r){const t=e.reduce((e,r)=>e+r.price*r.qty,0);return void 0===r?t:t*(1+r)}export{e as calculateTotal};

The status bar reports Minified: 275 → 115 bytes (58% smaller). Terser removed the comments and whitespace, renamed parameters and locals to single letters, turned the if statement into a conditional expression, replaced undefined with the shorter void 0, and kept the exported name calculateTotal intact through export { e as calculateTotal } so importers still work.

Options explained

  • Shorten variable names (mangle) renames local variables, parameters and functions declared inside other functions. Global names are left unchanged, because other scripts may use them. This option usually gives the biggest savings.
  • Compress code runs Terser's optimizer twice: it removes unreachable code, inlines constants, joins consecutive statements, simplifies conditionals and drops unused local functions and variables.
  • Keep license comments preserves comments that must stay for legal reasons: those starting with /*! or containing @license or @preserve. With it on, the example above keeps its /*! MyLib v1.2 | MIT */ banner.

With only Compress enabled, names stay readable (function calculateTotal(items,taxRate){...}), which is handy when you want a smaller file that you can still debug.

ES modules and modern syntax

Files containing import or export are detected automatically and minified as ES modules, which lets Terser treat top-level declarations as private to the module. Modern syntax such as classes, arrow functions, async/await, optional chaining and template literals is kept as is; Terser does not transpile to older JavaScript, so the output runs wherever the input ran.

Minification tips

  • Keep the original. Minified code is for delivery, not editing. Store the readable source in version control.
  • Combine with compression. Servers usually also compress files with gzip or Brotli. Minifying first still helps, because it removes content that compression cannot drop entirely, like comments and long names.
  • Use source maps in production builds so stack traces point to your original code. Build tools like Vite and webpack generate them alongside the minified bundle.
  • Watch for code that depends on names. Libraries that read function.name or use eval can behave differently after mangling. Turn off Shorten variable names if something breaks.

Errors

Terser needs valid JavaScript. A syntax error such as const a = {b: 1,,}; is reported with its position, for example Unexpected token: punc (,) (line 1, column 17). TypeScript and JSX must be compiled to JavaScript first. You can check syntax with the JavaScript Validator.

To read a minified file again, use the JavaScript Formatter. If you want the code to be hard to read rather than just small, see the JavaScript Obfuscator. Everything runs in your browser; your code is not uploaded.

Frequently asked questions

Is minified JavaScript safe to use in production?
Yes. Terser produces code that behaves the same as the original, which is why most build tools use it. Test your site after minifying, especially if code depends on function names.
How much smaller will my file get?
Typical hand-written code shrinks by 30–60%, depending on comments, whitespace and name lengths. The status bar shows the exact byte counts for your input.
Does the minifier convert ES6 to ES5?
No. Minification keeps your syntax level. Use a transpiler such as Babel or esbuild if you need to support older browsers.
Why are some names not shortened?
Global variables and functions are kept, because other scripts or HTML attributes may refer to them. In ES modules, exported names keep their public names.
Can I minify TypeScript or JSX?
Not directly. Compile it to plain JavaScript first; Terser only accepts standard JavaScript syntax.

Last updated September 26, 2026

Guides

Related tools