JavaScript Minifier
Minify JavaScript online, strip comments and whitespace to reduce bundle size.
Paste JavaScript and click Minify to strip whitespace and remove comments. Typical size reduction is 30 to 60%.
Use it for small scripts and quick deploy copies when a full build step is not available.
Input JavaScript
Minified Output
Why Minify JavaScript?
JavaScript is usually the biggest bottleneck in web performance. It has to be downloaded, parsed, compiled, and executed, all before your page becomes interactive. Every kilobyte counts. Minification strips the parts humans need (comments, indentation, blank lines) while keeping everything the browser needs.
A typical JavaScript file shrinks 30-60% after minification. That's not just faster downloads, it's faster parsing too. V8 (Chrome's JS engine) parses minified code faster because there's less text to process. For mobile users on slow connections, the difference between 200KB and 100KB of JS can mean seconds of load time.
This tool handles comment removal, whitespace collapsing, and basic operator spacing. For production use, build tools like Terser, esbuild, or SWC can also handle dead code elimination, tree shaking, and variable mangling.
What Minification Removes
| Element | Before | After | Savings |
|---|---|---|---|
| Comments | // Calculate total /* Multi-line */ | (removed) | 10-30% of file typically |
| Whitespace | Indentation, blank lines | Collapsed to minimum | 15-25% of file |
| Line breaks | One statement per line | Everything on fewer lines | 5-10% of file |
| Variable names* | calculateTotalPrice | a | Significant for large files |
| Dead code* | Unreachable branches | (removed) | Varies widely |
What this means for you: Items marked with * require parser-aware minifiers such as Terser or esbuild. This online tool handles comments and whitespace, the quick wins that do not risk changing behaviour. Use it for one-off jobs; use build tools for production.
JavaScript Minifiers in Build Pipelines
| Tool | Typical role | Notes | Common context |
|---|---|---|---|
| Terser | Parser-aware minification | Can mangle names, drop dead code, and simplify expressions | Webpack and Vite production builds |
| esbuild | Bundling and minification | Used when build speed matters and output size is still compact | Vite and CI pipelines |
| SWC | Compile and minify | Rust-based compiler used by several JavaScript frameworks | Next.js and transpilation-heavy projects |
| UglifyJS | Legacy minification | Mostly useful for older ES5 projects | Older build chains |
| Closure Compiler | Typed optimisation | Works well when code follows its annotation and module expectations | Specialised large codebases |
Real-World Size Savings
| Library | Original | Minified | Minified + Gzip |
|---|---|---|---|
| jQuery 3.7 | 282 KB | 87 KB (69%) | 30 KB |
| React 18 | 140 KB | 45 KB (68%) | 14 KB |
| Lodash | 544 KB | 71 KB (87%) | 25 KB |
| Three.js | 1.2 MB | 650 KB (46%) | 170 KB |
| Typical app bundle | 500 KB | 200 KB (60%) | 65 KB |
Full parser-based minification with variable mangling (the production builds shown above) cuts 50-70%; stripping whitespace and comments alone, which is what this tool does, typically cuts 30-60%. Add Gzip/Brotli compression (which your server should already enable) and you're typically looking at 85-90% total reduction. That 500 KB bundle becomes 65 KB over the wire.
Worked Example: Trimming an Inline Script
Aisha maintains a static pricing page with a small inline script that toggles monthly and yearly prices. There is no bundler because the page is a single HTML file.
1. Keep the readable script
She keeps a readable copy with comments in the source file so future pricing changes are easy to review.
2. Minify the deploy copy
The minifier removes comments and spacing from the small script before she places it into the published HTML.
3. Test click behaviour
She clicks the monthly and yearly tabs, checks the displayed prices, and confirms that keyboard focus still moves correctly.
4. Avoid editing output
If the script needs another change, she edits the readable source and minifies again. She does not edit the compressed output directly.
Minification Risks to Watch
| Risk | Why it happens | How to reduce it |
|---|---|---|
| Regex mistaken for comments | Simple text minifiers can misread slashes | Review code with regex literals after minifying |
| Template literal changes | Backtick strings can contain meaningful spaces and newlines | Check generated strings and HTML fragments |
| Missing source maps | One-off minifiers do not map output back to source | Use a build tool when production debugging matters |
| Inline event handlers | Small snippets can rely on surrounding HTML | Test the full page, not only the script text |
| Already compressed bundles | Some files are already minified by a build step | Check before and after byte counts before replacing files |
Safe JavaScript Minification Checklist
- Keep the readable source. The minified output is for delivery, not editing.
- Run behaviour checks. Click UI controls, submit forms, and inspect console errors after using the output.
- Use build tools for applications. Bundled apps need source maps, module handling, and parser-aware transforms.
- Avoid minifying TypeScript directly. Compile TypeScript to JavaScript first, then minify the JavaScript output.
- Do not minify secrets into client code. If a token appears in browser JavaScript, minification does not protect it.
One-Off Minifier or Build Tool?
Use the right level of tooling for the script. Small snippets and full applications have different needs.
| Scenario | Good fit | Why |
|---|---|---|
| Small inline script | One-off minifier | You only need to trim comments and whitespace |
| Static page without a build step | One-off minifier | A deploy copy can be smaller without changing your source file |
| React, Vue, or app bundle | Build tool | Modules, source maps, tree shaking, and syntax transforms need a pipeline |
| TypeScript project | Build tool | TypeScript must be compiled before JavaScript is minified |
Related Tools
How to use this tool
Paste your JavaScript into the input area
Click Minify JavaScript to compress
Copy the result or download as a .min.js file
Common uses
- Reducing JavaScript file size for production
- Stripping comments from code before deployment
- Quick minification for inline scripts
- Comparing file sizes before and after compression
Share this tool
Frequently Asked Questions
What does JavaScript minification do?
Will minification break my code?
Is my code sent to a server?
How much will my file shrink?
Should I minify in development?
What's the difference between minification and bundling?
What about source maps?
Does minification affect SEO?
What is Terser and when should I use it?
Can I minify ES6+ and TypeScript?
What's the difference between Terser and esbuild?
How do I minify automatically in my build?
Does this rename variables?
Can I minify a single inline script?
What should I do before minifying production code?
Why are source maps useful?
Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.