JavaScript Minifier
Free JavaScript minifier powered by Terser: compress and mangle code, keep license comments, support ES modules, and see bytes saved with gzip size.
How to use JavaScript Minifier
- 1Paste your JavaScript or open a .js file.
- 2Choose whether to compress and mangle names, and which comments to keep. Open More options for module mode and the ECMAScript target.
- 3Copy or download the minified code and check the bytes saved. Switch to Format or Validate if you need them.
What makes it better
- Terser compress and mangle can be switched on and off separately
- Comment policy: remove all, keep only license comments (/*! and @license) or keep everything
- Top-level names are left alone by default, with a toggle for keeping function and class names
- ES module input and an ECMAScript target (ES5 to ES2020+) are supported
- Shows before and after bytes, percentage saved and approximate gzip size
About JavaScript Minifier
This minifier runs Terser on your JavaScript to strip comments and whitespace, simplify expressions and shorten local variable names. It shows the size before and after, the percentage saved and an approximate gzip size, and lets you decide how aggressive to be. The same page also formats and checks syntax, and your code is parsed but never run.
Common uses
- Shrink a small script or bookmarklet before inlining it in a page.
- Check how much a snippet would save before wiring a build step.
- Produce a quick .min.js for a demo, a widget embed or an email-safe snippet.
- Compare compress-only against compress plus mangle to see what each contributes.
Example
Input
// Sum the prices in a cart
function calculateTotal(items) {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}
const cart = [
{ price: 4.5, quantity: 2 },
{ price: 10, quantity: 1 },
];
console.log("Total: " + calculateTotal(cart));
Result
function calculateTotal(t){let c=0;for(const a of t)c+=a.price*a.quantity;return c}const cart=[{price:4.5,quantity:2},{price:10,quantity:1}];console.log("Total: "+calculateTotal(cart));Good to know
- Minifying is not obfuscation or security: the output can be reformatted in seconds and still contains your logic, strings and any secrets in them.
- Mangling top-level names can break code that other scripts or inline HTML refer to, so it is off by default. In module mode Terser does rename non-exported top-level names because module scope is private; exports keep their names.
- Gzip size is approximate and comes from your browser's CompressionStream, so it can differ slightly from your server. If the browser lacks it, the gzip figure is hidden.
JavaScript Minifier FAQ
How do I minify JavaScript online?
Paste your script and the minified version appears next to it with the bytes saved. Leave compress and mangle on for the smallest result, or turn mangling off if you want readable variable names.
What is the difference between compress and mangle?
Compress rewrites code into shorter equivalent forms, such as folding constants or dropping unreachable branches. Mangle only renames local variables and parameters to short names. You can use either one alone.
Can minifying break my code?
Rarely, and usually when something depends on names. Code that reads Function.name, uses eval, or is referenced by name from another script can misbehave, which is why top-level names are kept and a keep-function-names option exists. Test the minified file before shipping it.
Does it keep license comments?
Yes, if you pick Keep license comments. Terser then preserves comments that start with /*! or contain @license or @preserve and removes the rest, which satisfies most open-source attribution requirements.
Can it minify ES modules with import and export?
Yes, tick ES module under More options. Exported names are preserved, but non-exported top-level names may be renamed because module scope is private. It does not bundle or resolve imports.