JavaScript Minifier
Minify and mangle JavaScript online with Terser for smaller bundles. Supports modern ES syntax, with compress and mangle options and the size saved.
Runs in your browser · Nothing uploaded · No sign-up
Something not working, or missing a feature? Send feedback
About the JavaScript Minifier
The JavaScript Minifier uses Terser, the minifier behind most JavaScript bundlers, to remove whitespace and shorten local variable names (mangling) for smaller files.
Everything runs in your browser, so your input is never uploaded to a server.
How to use the JavaScript Minifier
- Paste JavaScript or open a file.
- Choose whether to mangle names and apply compression optimisations.
- Copy or download the minified code.
Example
Input
export function calculateTotal(items, taxRate) {
// Sum the line totals, then add tax
const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0);
const tax = subtotal * taxRate;
return Math.round((subtotal + tax) * 100) / 100;
}Result
export function calculateTotal(t,c){const e=t.reduce((t,c)=>t+c.price*c.quantity,0),n=e*c;return Math.round(100*(e+n))/100}The comment is removed, local names are shortened and the two constants are merged into one declaration. The exported name calculateTotal is kept, so other modules can still import it.
Common mistakes
- Code that relies on function names. Mangling renames local functions and classes, so code that reads fn.name or constructor.name gets different values. Switch off mangling for such code.
- Shipping without a source map. Errors in minified code point to line 1 and short names. Keep the original file, or build with a bundler that writes source maps, for debugging.
- Top-level code disappears. Code is minified as an ES module, so top-level functions and variables that are never used or exported are removed. Export what other files need, or call it, and it is kept.
- Minifying JSON or TypeScript. The input must be JavaScript. Compile TypeScript first, and use the JSON Minifier for JSON.
Works well with the JavaScript Minifier
- JavaScript Formatter: make minified code readable again.
- JavaScript Compiler: run the minified code and check it still works.
- CSS Minifier: minify the stylesheet that goes with it.
Frequently asked questions
What does mangling do?
It renames local variables and function parameters to short names. Global names and object properties are left alone, so behaviour does not change.
Does it support modern syntax?
Yes, ES2015+ features such as modules, classes, async functions and optional chaining are supported.
Is it as small as my bundler’s output?
It uses Terser, which most bundlers use, so a single file comes out the same. Bundlers also remove unused exports across files, which a single-file minifier cannot do.
Is my code uploaded?
No. Terser runs in your browser, so the code never leaves your device.
Related tools
JSON Minifier
Minify JSON online by removing all unnecessary whitespace, and see how many bytes you saved. Invalid JSON is reported with its line and column.
HTML Minifier
Minify HTML online: remove comments and collapse whitespace while keeping pre, textarea, script and style blocks intact. See the size saved instantly.
CSS Minifier
Minify CSS online: strip comments, whitespace and redundant semicolons to shrink your stylesheet, and see the bytes saved. Runs in your browser.
XML Minifier
Minify XML online by removing whitespace between tags, with an option to keep comments. Malformed XML is reported with its location.
SQL Minifier
Compress SQL queries onto a single line online, removing comments and redundant whitespace. Useful for logs, config files and embedding SQL in code.
JSON Formatter
Format and beautify JSON with configurable indentation and optional key sorting. Errors are reported with exact line and column.