How to minify JavaScript online
Three steps, about a minute.
1
Add your code
Paste JavaScript, drop one or more .js files onto the editor, or upload them. Several files are joined in order. Syntax errors show the exact line and column, with a button that jumps to the error.
2
Pick a preset
Start with Balanced. Open Minifier settings to change compression passes, name mangling, top-level scope, console removal, comments or source maps.
3
Copy or download
Check the size and gzip numbers, then copy the output or download the .min.js file and its .map. Your last 20 runs are kept in local history.
What minification does to your code
A minifier removes whitespace and comments, shortens local names, and rewrites expressions into equivalent shorter forms. The code still does exactly the same thing.
Before · 298 bytes
// Sum the price of every item in the cart
function calculateTotal(items, taxRate) {
let subtotal = 0;
for (const item of items) {
subtotal += item.price * item.quantity;
}
const tax = subtotal * taxRate;
if (tax > 0) {
return subtotal + tax;
} else {
return subtotal;
}
}
After (Balanced) · 105 bytes
function calculateTotal(t,c){let n=0;for(const c of t)n+=c.price*c.quantity;const o=n*c;return o>0?n+o:n}
Comments and whitespace are gone, the parameters became t and c, and the if/else became a ternary. calculateTotal keeps its name because it's a global that other scripts may call. The Top-level scope option renames globals too.
Safe vs Balanced vs Aggressive
Each preset is a set of Terser options. Choose based on how self-contained your script is.
Rule of thumb: use Balanced. Use Safe if something breaks after minifying. Only use Aggressive when no other script on the page reads your global variables.
Tips for smaller, safer JavaScript
Minification is one step. These habits get the rest of the savings without surprises.
✓
Serve gzip or Brotli
Minify and compress together. The gzip figure above is roughly what visitors download. Brotli on the server is usually another 10–20% smaller.
✓
Ship a source map
Keep the .map next to the .min.js file so production errors point to real lines. If you don't want the original source to be public, upload the map to your error tracker instead.
✓
Test after dropping console
Drop console removes the whole call, including its arguments. Code like console.log(counter++) changes behaviour, so run your tests on the minified build.
Frequently asked questions
Common questions about minifying JavaScript.
Is my JavaScript uploaded to a server?
No. Minification runs in your browser using the Terser library, which is loaded from the jsDelivr CDN. Your code never leaves your device, so private source and API keys stay local.
Does this minifier support ES6 and newer JavaScript?
Yes. It uses Terser 5, which parses modern JavaScript, including arrow functions, classes, class fields, private #members, async/await, async generators, optional chaining (?.), nullish coalescing and assignment (??, ??=), BigInt, import and export. The old UglifyJS engine can't parse most of these.
What is the difference between Safe, Balanced and Aggressive?
Safe runs one compression pass and keeps class and function names, for code that relies on Function.name. Balanced runs two passes, removes debugger statements and targets ES2020 output. Aggressive runs three passes, mangles top-level names, removes console calls and strips every comment. Only use it for self-contained bundles, because top-level mangling renames globals that other scripts may use.
Will minifying break my code?
With the Safe and Balanced presets, correct code keeps behaving the same. Problems usually come from three things: top-level mangling of globals that other scripts reference, dropping console calls whose arguments have side effects, and code that depends on function or class names. Test the minified file before deploying.
What is a source map and do I need one?
A source map is a .map file that links minified code back to the original lines, so browser dev tools and error trackers show readable stack traces. Turn on Source map in the settings, download both files, and serve the .map next to the .min.js file. The minified output already ends with the matching //# sourceMappingURL comment.
How much smaller will my JavaScript get?
Hand-written JavaScript with comments usually shrinks by 40–70% before compression. Code that is already bundled or minified shrinks much less. The tool shows the gzip size for both input and output, which is closer to what is actually sent over the network.
Can I un-minify or beautify JavaScript?
Yes. Switch to Beautify mode to reformat minified code with 2 or 4 space indentation. The structure becomes readable again, but mangled names such as t and e can't be turned back into the original names.
Are license comments kept?
By default, comments starting with /*! or containing @license, @preserve or @cc_on are kept, since many open-source licenses require attribution to be preserved. In the settings you can also remove all comments or keep all of them.
Can I minify several files into one?
Yes. Select or drop several .js files at once. They're joined in the order you picked them, each separated by a comment with its file name, and then minified as one script.
Is the JavaScript Minifier free?
Yes. It's free, needs no sign-up, and has no limit on how many files you minify.