What it does
The JavaScript Minifier makes scripts smaller so they download and parse faster. It uses Terser, the minifier behind most modern build tools, to remove whitespace and comments, simplify expressions and shorten local variable names. The result shows how many bytes you saved.
How to use it
- Paste your code into Input, or click Sample.
- Click Minify.
- Leave Shorten names on for the smallest output; turn it off if other code needs your function's local names.
- Tick Keep license comments to keep
/*! … */and@licensecomments. - Copy or download the result.
Example
function total(items) {
// add up the prices
let sum = 0;
for (const item of items) {
sum += item.price * item.qty;
}
return sum;
}
Minified:
function total(t){let o=0;for(const n of t)o+=n.price*n.qty;return o}
The function name total is kept because other code may call it; only the names inside it are shortened.
Good to know
- Minifying is safe for normal code. Code that reads its own variable names at run time, such as
evalorFunction.prototype.toString, may need Shorten names off. - Your server should also send scripts compressed with gzip or Brotli. Minifying and compressing together give the smallest download.
- If the code has a syntax error, the minifier stops and shows the line and column.
FAQ
Can I turn minified code back into readable code? Use the JavaScript Formatter. Layout comes back; shortened names and removed comments do not.
Does it support modern JavaScript? Yes: modules, classes, async functions, optional chaining and other recent syntax.