How to minify JavaScript
- Paste your code into JavaScript.
- The minified code appears on the right. The status line shows the size before and after, or the line and column of a syntax error.
- Copy it or download it as script.min.js.
What Terser does
Minifying the example shows each step:
- Removes comments and whitespace. The comment line and all indentation disappear.
- Mangles local names.
callback,delayandtimerbecomee,tandn. - Compresses code. Two statements in a row are joined with a comma, and single quotes are swapped for double quotes where it doesn’t cost anything.
- Keeps modern syntax. Arrow functions, default parameters, async functions, optional chaining and import and export statements stay as they are.
Minified is not protected
Minified code is harder to read but not secret. Anyone can paste it into the JavaScript formatter and get indented, readable code back, just with short variable names. Never put API keys, passwords or anything private in code that runs in the browser.