How to minify JavaScript
Paste the code
Paste your JavaScript or open a .js file, or try “Example”.
Pick the options
Shortening variable names is on; you can keep function names if your code relies on them.
Copy or download
Press “Minify” to see the savings, then copy or download the .min.js file.
Options
| Option | What it does | When to change it |
|---|---|---|
| Shorten variable names | totalPrice → t | Turn it off if you want to read the output. |
| Keep function and class names | Keeps fn.name and class.name | If your code or a library relies on function names. |
| Keep licence comments | Keeps /*! ... */ and @license | Leave it on for open-source libraries. |
Tips
Globals are not renamed. Top-level variables keep their names, because other scripts on the page may use them. In modules (import/export) everything is renamed.
A syntax error? You get the line, column and reason, and a button that takes you there.
Add gzip too. Minified code plus gzip or Brotli on the server gives the smallest download.
FAQ
Will my code still work after minifying?
Yes, for valid code. We tested 13 well-known libraries including jQuery, Lodash, D3, Vue and Moment, plus test programs with Arabic text, ran each before and after minifying and compared the results: they matched.
Which engine does it use?
Terser 5.51 (BSD licence), the engine used by popular build tools such as webpack and Vite.
How much does JavaScript minification save?
Usually 50% to 70%. For example jQuery goes from 279 KB to 85 KB and Lodash from 531 KB to 69 KB.
Does it support import, export, classes and ?.?
Yes, all modern JavaScript. If the code has import or export, it is treated as an ES module automatically.
Can minified code be turned back into the original?
You can make it readable with our JavaScript Formatter, but shortened names and removed comments don’t come back. Always keep your original file.
