Code Minifier
Minify JavaScript, CSS, and HTML to reduce file size and improve page load performance.
Why I Built This Minifier
I use this minifier when I need to quickly compress some code without setting up a build pipeline. Sometimes you just need to minify one file - maybe a quick script for a client, or an inline style that got too long. I didn't want to spin up Webpack or Vite just for that.
The tool runs entirely in your browser. I chose Terser for JavaScript (same as what Webpack uses), CSSO for CSS, and html-minifier-terser for HTML. These are battle-tested libraries that I trust with my own production code.
How I Actually Use It
My typical workflow: paste in some code, check the compression stats, and copy the output. I like seeing the percentage savings - it helps me decide if minification is even worth it for smaller files (spoiler: for anything under 1KB, the gains are often negligible).
- JavaScript - Variable mangling, dead code removal, ES6+ support. I get 40-60% reduction on most files.
- CSS - Shorthand optimization, color compression. Usually saves 20-40%.
- HTML - Whitespace removal, comment stripping. Modest gains, but every byte counts.
I often use this alongside the JSON Formatter when I need to switch between readable and compact formats, or the Diff Checkerto verify the minified output still contains what I expect.
When Minification Actually Matters
I've seen developers obsess over minification when it barely makes a difference. Here's my honest take: if your JavaScript bundle is under 10KB gzipped, don't lose sleep over minification settings. Focus on code splitting instead.
That said, minification does add up on larger projects. On a recent client project, we shaved 180KB off the initial bundle - that's real savings for mobile users on slow connections.
- Faster page loads - Especially on mobile and emerging markets
- Lower bandwidth costs - Matters when you're paying per GB
- Better Core Web Vitals - Google uses these for ranking
JavaScript: What Gets Removed
I'm always amazed by how aggressive Terser can be while keeping code functional:
- Whitespace and comments - Obvious, but also the biggest gains
- Variable renaming -
userAuthenticatedbecomesa - Dead code - Unreachable branches get stripped
- Constant folding -
1 + 2becomes3
CSS: Smarter Than You'd Think
CSS minification isn't just about removing whitespace. CSSO actually understands CSS and can make smart optimizations:
- Shorthand conversion - Four margin values become one when possible
- Color optimization -
#ffffffbecomes#fff - Zero units -
0pxbecomes0 - Duplicate removal - Redundant declarations get merged
HTML: The Modest Gains
I'll be honest - HTML minification usually saves the least. But for large pages or email templates, it can still help:
- Whitespace collapse - Multiple spaces become one
- Comment removal - Including conditional comments if you want
- Attribute cleanup - Optional quotes and values removed
- Inline minification - Embedded CSS and JS get processed too
Related Articles
- Code Minification: Complete Guide to Reducing File Size
- JavaScript Beautifier: Making Sense of Minified Code
Frequently Asked Questions
Is my code secure?
Yes - and this matters to me too. All minification runs in your browser. Your code never touches my servers. I built it this way because I wouldn't use a tool that sent my client's code somewhere.
Should I use minified code during development?
Please don't. I've debugged enough minified code to know it's painful. Keep your source files readable, minify only for production, and always generate source maps if your build tool supports them.
How do I debug minified code?
Source maps are your friend. Most bundlers generate them automatically. They let you see your original code in DevTools even when the browser is running minified code. I always enable them in staging, disable in production.
Does minification make code run faster?
Not really - the code executes the same way. The benefit is faster downloads. Parse time might be slightly faster with smaller files, but it's negligible. Don't expect minification to fix performance issues in your logic.