JavaScript Minifier & Beautifier
Compress JavaScript with Terser, with options to mangle names, compress code, drop console calls, and keep license comments, or reformat code into readable, indented source.
Your data stays in your browser. This tool processes your input locally and does not upload it to a server.
Input
Output
What does a JavaScript minifier do?
A JavaScript minifier shrinks source code by removing whitespace and comments, shortening local variable names and simplifying expressions, which cuts download size. This tool minifies with Terser and beautifies with js-beautify in your browser. You can toggle name mangling, compression, console removal and license comments, and syntax errors are reported with a line and column.
The minify options
Mangle names shortens the names of local variables, parameters and inner functions to one or two letters. Top-level names are kept, so a function declared at the top of a plain script, such as totalPrice, is still callable by other scripts on the page. Compress lets Terser rewrite code into shorter equivalents, for example collapsing statements and removing unused local code.
Drop console.* removes calls such as console.log from the output. It needs Compress to be on, so the checkbox is disabled otherwise. Keep license comments retains comments that Terser treats as important, such as those containing @license or @preserve, and removes the rest. Each run shows the bytes saved.
Beautify and error reporting
Beautify re-indents code with two spaces, four spaces or tabs, keeps up to two blank lines between blocks and ends the file with a newline. It is meant for reading minified or badly formatted scripts. It does not parse the program the way a minifier does, so it will not report a syntax error.
Minify does parse the code. When the input is not valid JavaScript, the tool shows Terser’s message with the line and column instead of output. Upload a .js or .mjs file up to 5 MB, or paste code, and copy the result or download it as script.js.
Examples
Minify with default options
Input
function totalPrice(items) {
let total = 0;
for (const item of items) {
total += item.price * item.quantity;
}
return total;
}
console.log(totalPrice([{ price: 10, quantity: 2 }]));Output
function totalPrice(t){let o=0;for(const c of t)o+=c.price*c.quantity;return o}console.log(totalPrice([{price:10,quantity:2}]));The local names items, total and item became t, o and c. The top-level function name totalPrice is unchanged. The short names Terser picks can differ between versions.
Drop console calls
Input
Same code with Compress and Drop console.* both onOutput
function totalPrice(t){let n=0;for(const o of t)n+=o.price*o.quantity;return n}The console.log statement is gone and the function declaration remains. The tool output is a single line, and the exact short names may differ.
A syntax error
Input
function (Output
Unexpected token: punc (() at line 1, column 9Common mistakes and edge cases
- Dropping console calls that you rely on. Drop console.* removes every console.* call, including console.error that you may want in production.
- Expecting mangling to rename top-level names. Terser keeps them in this tool, which is correct for scripts shared across files but means the file is not fully obfuscated.
- Using minification as security. Minified code is smaller, not secret, and a beautifier restores a readable layout in seconds.
- Minifying code that depends on function names, such as code that reads fn.name or uses Function.prototype.toString, or that relies on class names for registration. Mangling can change those.
- Beautifying and assuming the code is valid. Beautify reformats without checking syntax, so run Minify if you want a syntax check.
- Shipping without source maps when you need to debug production errors. This tool does not produce a source map.
How to use this tool
- Paste JavaScript or upload a .js file.
- Pick minify options such as mangling and dropping console calls.
- Minify or Beautify, then copy or download script.js. Syntax errors show a line and column.
Frequently asked questions
Is my code sent to a server?
No. Terser and js-beautify run inside your browser tab, so your source never leaves your device. This makes the tool reasonable for unreleased or proprietary code. You can confirm it by watching your browser’s network panel while you minify: no request carrying your source is made, and the page does not store your input once you close the tab.
Why were my top-level function names not shortened?
Renaming top-level variables is only safe when the file is a module or wrapped in a function, because other scripts might call those names. This tool uses Terser’s default, which leaves top-level names alone, so the output works when loaded with a normal script tag. Bundlers and Terser’s toplevel option can rename them when the whole program is known.
What does Compress do beyond removing whitespace?
Compress applies Terser’s optimizations to the program structure. Examples include evaluating constant expressions, joining consecutive variable declarations, removing code that can never run, and replacing if statements with shorter conditional expressions. These rewrites keep the behavior of valid code the same, but they are the step most likely to expose bugs in code that depended on unusual evaluation order.
Can I minify modern syntax such as async functions or optional chaining?
Yes. Terser parses current ECMAScript syntax, including async functions, optional chaining, classes and the export keyword. The tool does not transpile, so the output uses the same language features as the input, and the minified file only runs in browsers that support that syntax. If you must support old browsers, transpile with a build tool first and minify the result. A syntax error in the input is reported with its line and column.
What happens to comments?
By default every comment is removed. With Keep license comments on, comments that Terser recognizes as important, such as ones containing @license or @preserve or starting with an exclamation mark, are kept, which is how license headers survive. All other comments are removed to save space. Beautify never removes comments, because it only changes whitespace and indentation, so use it when you want to read the original comments.
References
Last reviewed
Related tools
CSS Minifier & Beautifier
Minify CSS to cut file size or beautify it for reading.
Formatters & BeautifiersJSON Formatter & Validator
Format, minify, and validate JSON with clear error locations.
Formatters & BeautifiersSQL Formatter
Format and minify SQL with keyword case control.
Formatters & Beautifiers