About this tool
Minify JavaScript for production with Terser, the minifier used by webpack, Vite, Rollup and most build tools. It removes whitespace and comments, shortens local variable names, and rewrites code into shorter equivalents. The status line shows the saving before and after gzip.
What the options do
- Compress rewrites code:
if (a) { b() }becomesa&&b(), constant expressions are calculated, and unreachable code is dropped. - Shorten names renames local variables and parameters to single letters. Property names and top-level names are left alone, so other scripts can still use them.
- Top-level names too also renames top-level functions and variables. Only use it for modules or bundles that nothing else calls into.
- ES module parses the code as a module (strict mode,
importandexportallowed). - Keep function and class names preserves
.name, which some frameworks and error trackers rely on. - Remove console.* deletes logging calls from production code.
Comments starting with /*! or containing @license or @preserve are kept by default, as most open-source licences require. Syntax errors are reported with their line and column.
FAQ
How do I minify JavaScript?
Paste the code. It is minified with Terser as you type, and the status shows the size reduction. Copy or download the result.
Is minified code slower?
No. It runs the same and downloads and parses faster.
Why did my code break after minifying?
Usually because something relies on names: code that reads function.name, or other scripts calling top-level functions after “Top-level names too” renamed them. Turn on “Keep function and class names” or turn off the top-level option.
Should I minify if my server uses gzip?
Yes. They work together: minifying removes things gzip can’t, such as comments and long local names.
Is my code uploaded?
No. Terser runs in a background worker in your browser.