JavaScript Formatter
Beautifies minified or messy JavaScript with your chosen indent and brace style.
Minify JavaScript with Terser, the minifier behind most modern build tools. Shorten variable names, drop dead code, and see the size saving raw and gzipped.
.js file.Terser parses the code into a syntax tree, simplifies it, and prints it back with as few characters as possible.
import and export and treats top-level names as local, which allows more renaming.console.log and friends.Input:
// Adds tax to a price
function priceWithTax(price, rate) {
const tax = price * rate;
if (false) {
console.log('never runs');
}
return price + tax;
}
window.priceWithTax = priceWithTax;Output with all options on except ES module:
function priceWithTax(i,r){return i+i*r}window.priceWithTax=priceWithTax;The dead if (false) block and the comment are gone, tax is inlined, and the parameters are shortened. The global function name is kept.
eval, can break when names are shortened. Untick Shorten names in that case.Minifying makes code smaller and faster to download; the result is hard to read as a side effect. Obfuscation deliberately makes code hard to understand and often makes it bigger and slower.
Rarely. The usual causes are code that depends on function or variable names at run time, or missing semicolons combined with unusual line breaks. Test the minified file before you ship it.
Gzip already compresses repeated whitespace and long names well. The gzipped figures are what visitors actually download from a server with compression turned on.
No. Terser runs in your browser, and your code never leaves your device.
Often used together with the JavaScript Minifier.
Beautifies minified or messy JavaScript with your chosen indent and brace style.
Minifies CSS and shows the size saving, raw and gzipped.
Beautifies or minifies JSON.