What is JS Minifier?
JS Minifier compresses JavaScript code by removing whitespace, comments, and shortening variable names using the Terser engine. This reduces file size for faster page loads and lower bandwidth costs while preserving the code's functionality.
The minifier runs Terser locally on your code: it strips whitespace and comments, renames local variables to single letters when mangling is on, applies safe AST transforms when compression is on, and can drop console.log calls. The tool reports the original size, minified size, and percentage savings so you can confirm the gain before shipping.
How to use
- Paste your JavaScript code into the input editor, or upload a .js file.
- Pick your minification options: toggle mangling (shortens variable names), compression, and whether to strip out console.log calls.
- Click Minify to process the code. Check the size reduction, then download the minified file or copy it to your clipboard.
When to use
- Compressing a JavaScript bundle before shipping to a CDN that has no built-in build step.
- Stripping comments and console statements out of a library before pasting it into a CMS theme.
- Producing a one-shot minified snippet for a chat widget, ad pixel, or third-party script tag.
Result
You have a 45KB utility library with extensive comments and long variable names. Paste it in, enable mangling and compression, and get a 12KB output — a 73% reduction ready for production deployment.
FAQ
- Will minification break my code?
- Terser is conservative by default and preserves semantics. Mangling only renames variables that are not exported; compression skips transforms it cannot prove safe. If you rely on Function.name or eval-ing source, turn mangling off for that file.
- How much size reduction should I expect?
- Typical JavaScript shrinks 40 to 70%. Code with long comments, verbose variable names, or unused branches shrinks more. Code that is already terse, or made up mostly of string literals, shrinks less. After gzip the difference narrows further.
- What is the difference between minify and compress and mangle?
- Minify is the umbrella term. Compress applies code-level transforms like folding constants and removing dead branches. Mangle renames identifiers to short names. You can run any of them on its own; combining all three usually gives the smallest output.
- Should I minify code that I will gzip or brotli on the server anyway?
- Yes. Gzip reduces redundancy in text, but it does not rename long variable names or remove unused branches. Minified code compresses better and parses faster once it loads. The two stages add up rather than overlap.
- Does this work for TypeScript or modern ES2022 syntax?
- Pure TypeScript needs to be compiled first because Terser only consumes JavaScript. Modern ES syntax up to ES2022 (private fields, top-level await, optional chaining) is parsed directly without a Babel transform.
Related Tools
Structured Data Generator
Generate JSON-LD schema markup for SEO
Webpage to PDF
Capture a webpage as a PDF
Privacy Policy Generator
Generate a privacy policy for your site
Terms of Service Generator
Generate a terms of service document
Cookie Consent Generator
Generate cookie consent banner code
CSS Minifier
Minify CSS code to reduce file size