About the JS minifier
A JavaScript minifier reduces file size by removing whitespace and comments, shortening local variable names and simplifying code where the result behaves the same. Smaller scripts download and parse faster.
This minifier uses Terser, a widely used JavaScript compressor. It supports modern JavaScript and reports syntax errors with a readable message.
How to use the JS minifier
- Paste your JavaScript into the Input editor, or click Load sample.
- Click Minify code or press Ctrl + Enter (Cmd + Enter on Mac).
- If there is a syntax error, read the message, fix the code and try again.
- Click Copy result to copy the minified script.
Example
Minify a function
Input
// Adds tax to a price
function priceWithTax(price, taxRate) {
const tax = price * taxRate;
return Math.round((price + tax) * 100) / 100;
}
console.log(priceWithTax(19.99, 0.2));Output
function priceWithTax(n,o){const t=n*o;return Math.round(100*(n+t))/100}console.log(priceWithTax(19.99,.2));Parameter names are shortened; the top-level function name is kept because other scripts may call it.
Common errors and how to fix them
SyntaxError: Unexpected token: operator (<)
The code contains JSX or TypeScript, which plain JavaScript minifiers can't parse. Build it with your bundler or tsc first, then minify the output.
The minified code throws ReferenceError
The original code depended on a variable or function name, for example through eval or by reading function.name. Avoid those, or minify with name mangling turned off.
Minified file is barely smaller
Most of the size is string data or the code is already minified. Serve it with gzip or Brotli compression, which shrinks text far more than minification alone.
Good to know
- Local variable and function names are shortened (mangled). Global names and object property names are kept, so other code can still use them.
- Regular comments are removed. Licence comments that start with
/*!or contain@licenseare kept. - Input must be JavaScript. TypeScript and JSX need to be compiled to JavaScript first.
- Minification runs on the server, and your code isn't stored. Input is limited to 1 MB, and requests are rate-limited.
Frequently asked questions
Is minified code harder to reverse engineer?
Slightly, because names are shortened, but minification is not protection. Anyone can reformat the code and read its logic, so never put secrets in client-side JavaScript.
Why do I get a syntax error for code that runs in my project?
Your project may compile TypeScript, JSX or other syntax before it runs. Paste the compiled JavaScript output instead of the source.
Should I minify code by hand for production?
Most build tools, such as Vite, webpack and Next.js, minify automatically. This tool is handy for snippets, embeds and quick checks.
How do I minify JavaScript from the command line?
Run Terser directly: npx terser input.js --compress --mangle -o output.min.js. Add --source-map to also write a source map, so errors in the minified file still point to your original lines.