How to use the JavaScript Minifier tool
- Paste or open your JavaScriptPaste your code, or click “Open file” to load a .js or .mjs file.
- Choose optionsCompress, shorten variable names, treat the code as an ES module, and keep license comments.
- MinifyClick “Minify JavaScript”. Syntax errors are reported with the line and column.
- Copy or downloadCopy the result or download it as a .min.js file.
Features
- Industry-standard engineUses Terser, the minifier behind webpack, Vite and many other tools.
- Variable manglingRenames local variables and functions to short names like a and b.
- Dead-code removalDrops unreachable code, simplifies expressions and joins declarations.
- Modern syntaxUnderstands classes, arrow functions, async/await, optional chaining and ES modules.
- Clear error messagesFind mistakes quickly with the exact line and column of syntax errors.
Why minify JavaScript?
JavaScript is often the heaviest part of a web page to download, parse and run. Minifying reduces file size, commonly by 30–60% for readable source code, so scripts download faster and pages become interactive sooner, especially on phones.
What the options do
| Option | Effect |
|---|---|
| Compress | Rewrites code more efficiently: removes unreachable code, folds constants, shortens conditions |
| Shorten variable names | subtotal becomes t inside functions |
| Also shorten top-level names | Renames global functions and variables too; only safe if no other script uses them |
| ES module | Enables import/export and strict mode |
| Keep license comments | Preserves /*! … */ and @license comments |
Best practices
- Keep the original. Minified code is hard to read; always edit your source and minify again.
- Test after minifying, especially with “shorten top-level names”, which can break code that other scripts call by name.
- Serve with compression. Gzip or Brotli on your server stacks on top of minification.
- Use a build tool for big projects. For apps with many files, bundlers like Vite or webpack minify automatically.
About this tool
The minification engine, Terser (BSD license), is loaded from a public CDN the first time you minify, then runs entirely in your browser. Your code is never uploaded. Also try the CSS Minifier, the HTML Minifier, and the JSON Formatter.
Frequently asked questions
How do I minify JavaScript?+
Paste your code or open a .js file, choose the options and click “Minify JavaScript”. Copy or download the result.
Will minified code work the same?+
Yes, with the default options. Test carefully if you enable “Also shorten top-level names”, since other scripts may rely on global names.
Does it support modern JavaScript?+
Yes. Terser understands ES2020+ syntax, including classes, async/await, optional chaining and ES modules.
Why do I get a syntax error?+
The code contains invalid JavaScript at the reported line and column. Fix it and minify again. TypeScript and JSX must be compiled first.
Is my code uploaded?+
No. The Terser engine is downloaded to your browser and your code is processed locally.