JS Minifier
Minify JavaScript code
About JS Minifier
JS Minifier compresses JavaScript with Terser in your browser. Terser parses the code first, so the result behaves like the original: code written without semicolons, a return followed by a line break, regular expressions, and expressions such as a - -b are handled. Names local to functions are shortened, global names and object properties are kept, unreachable code such as an if (false) block is removed, and every comment is dropped. Modern syntax is accepted, including classes, async functions, optional chaining, and BigInt, and so are import and export lines. TypeScript is not: convert it first.
Example
No semicolons in the input; Terser adds them, puts everything on one line, and renames the locals.
Input
function total(prices) {
let sum = 0
for (const price of prices) sum += price
return sum
}
console.log(total([1, 2]))Minified output
function total(o){let t=0;for(const l of o)t+=l;return t}console.log(total([1,2]));How to minify JavaScript
- 1Paste your script into "Input".
- 2Click "Minify".
- 3Read "Minified output" and the characters-saved line; if the code does not parse, Error: and Terser's message appear instead.
- 4Click "Copy", or "Download" to keep "minified.js".
Formats and limits
- Input
- JavaScript, scripts or ES modules
- Output
- Minified JavaScript on one line, saved as minified.js
- Settings
- Compress and mangle on, comments off, top-level names kept
- Errors
- Terser's message, without line or column
Where your script is processed
Terser is downloaded once, on your first click on "Minify", and then works on your device: the script is not uploaded. A failed minification is the exception, since the error message shown, with quoted strings, long numbers, and addresses replaced, is reported to our error log with the tool's name and your browser's name and version; an unexpected failure of the page is reported the same way.
Frequently asked questions
Will minified code behave the same?
Yes. Terser only applies transformations that keep the behavior of code it could parse, including code written without semicolons; a return followed by a line break still returns nothing, as in the original.
Does it rename variables?
Yes, but only local ones: variables and parameters inside functions get one-letter names, as total(prices) becoming total(o) in the example. Top-level names and object properties are kept, so other scripts can still call them.
Can it minify TypeScript?
No. Type annotations are a syntax error for Terser. Use Code Minifier in TS mode, which removes the types and minifies in one step, or run TypeScript to JavaScript first and paste its output here.
Does it show where a syntax error is?
No. Only Terser's message is shown, for example Name expected, without its line and column. Paste the code into Code Formatter to see the position of the first syntax error.