How to use the JavaScript Minifier
- Paste your JavaScript or open a
.jsfile. - Keep Compress and Mangle names on for the smallest output; tick ES module for code with
import/export. - Optionally remove
consolecalls and choose which comments to keep. - Copy the result or download it as
.min.js.
What does a JavaScript minifier do?
Minification makes JavaScript smaller without changing what it does. It removes whitespace and comments, shortens local variable and function names, and rewrites code into shorter equivalent forms. Smaller files download and parse faster, which helps page speed and Core Web Vitals — especially on mobile.
This tool runs Terser, the minifier behind Vite, webpack and Rollup, directly in your browser.
The main options
| Option | What it does | Risk |
|---|---|---|
| Compress | Removes unreachable code, folds constants (60 * 60 → 3600), simplifies conditions and joins statements | Very low |
| Mangle names | Renames local variables and parameters to one or two letters | Low — code that uses eval or Function.name may break |
| Mangle top-level | Also renames global functions and variables | Breaks code that other scripts call by name |
| ES module | Parses import/export and enables strict mode and top-level mangling | None for real modules |
| Remove console.* | Drops console.log and similar calls | Removes logs you may want in production |
Minification vs compression
Minification and gzip/Brotli work together. Minifying typically removes 30–60 % of a file; the server’s gzip or Brotli compression then shrinks what is left by another 60–70 %. The stats above show both: the minified size and the gzipped size that will actually travel over the network.
Keep license comments
Open-source licenses such as MIT require the copyright notice to stay with the code. By convention these comments start with /*! or contain @license, and the default setting keeps them.
Troubleshooting
- Syntax error: the line and column are shown. TypeScript and JSX must be compiled to JavaScript first.
- Code stops working after mangling: turn off Mangle top-level names; if that does not help, check for
evalor code that reads function names. - Need a readable version again? Use the JavaScript formatter to beautify minified code.
Tools that pair well with the JavaScript Minifier
- HTML Minifier — Shrink HTML pages and templates by removing comments and redundant whitespace, minifying inline <style> and <script>, and cleaning up attributes — while keeping the layout identical.
- JSON Minifier — Remove all unnecessary whitespace from JSON, validate it at the same time and see exactly how many bytes you save — before and after gzip.
- Website Compression Test — Enter a URL to see which compression your server sends for each Accept-Encoding, how many bytes it saves, whether its CSS and JavaScript are compressed, and what Brotli could save.
- XML Minifier — Compact XML documents, feeds, sitemaps and SOAP payloads by removing indentation and comments — with a well-formedness check so nothing breaks.
Frequently asked questions
Is Terser better than UglifyJS?
Will minified code behave exactly the same?
eval, with or function names at runtime; turn mangling off for such code.