Minification is the last step before code ships, and it is the step most people either skip or apply blindly. Done right it cuts CSS and JavaScript by 30–60% with zero change in behaviour. Done wrong it breaks a site in ways that only show up in production, because the minified file is the one nobody reads. This guide explains what minifiers actually do, how much they save compared to compression, when they break things, and how to keep debugging possible afterwards.
What a minifier removes
- Whitespace, line breaks and indentation.
- Comments.
- Redundant syntax: the last semicolon before
}, unnecessary quotes in HTML attributes,0px→0,#ffffff→#fff. - In JavaScript, with a real minifier: local variable names shortened (
userAccountBalance→a), dead code removed, some expressions simplified.
Before:
/* Header styles */
.site-header {
background-color: #ffffff;
padding: 0px 16px;
margin-bottom: 24px;
} After:
.site-header{background-color:#fff;padding:0 16px;margin-bottom:24px} 128 bytes to 70. The Code Minifier handles CSS, JavaScript, HTML and JSON and shows the before/after size.
Minification vs. compression: you need both
Gzip and Brotli compress the file on the wire; the browser decompresses it. They are very good at repeated patterns, which is exactly what whitespace and long variable names are. So the saving from minifying an already-compressed file is smaller than the raw numbers suggest:
| File | Raw | Minified | Raw + Brotli | Minified + Brotli |
|---|---|---|---|---|
| Typical 100 KB CSS | 100 KB | 68 KB | 14 KB | 11 KB |
| Typical 300 KB JS | 300 KB | 140 KB | 70 KB | 42 KB |
Two things follow. First, check that compression is on (the HTTP Header Checker shows content-encoding: br or gzip); if it isn’t, that fix is worth ten times more than minification. Second, minification still wins on top of compression, especially for JavaScript, where variable renaming removes information compression can’t.
Where it breaks things
- JavaScript that relies on names. Code using
function.name,eval, or a global variable the minifier renamed. Mark such names as reserved, or don’t mangle that file. - Automatic semicolon insertion. JavaScript without semicolons that depends on line breaks to separate statements can change meaning when the breaks are removed. A statement starting with
(or[after a line without a semicolon is the classic case. Lint for it. - CSS hacks and comments that matter. Old IE hacks,
/*! preserved */license comments (good minifiers keep/*!), and the rare stylesheet where whitespace insidecalc()matters:calc(100% - 10px)needs the spaces around-, and a bad minifier removes them. - HTML with
<pre>or inline scripts. Collapsing whitespace inside<pre>or<textarea>changes content. Removing whitespace between inline elements can change rendering (two buttons that had a space between them now touch). - Templates with placeholders. Minifying a PHP, Liquid or Twig template before rendering can break the template syntax. Minify the output, not the source.
Keep debugging possible: source maps
A source map is a file that tells the browser how the minified code maps back to the original, so DevTools shows readable code with real names and line numbers even in production. Build tools (Vite, webpack, esbuild, the Sass compiler) generate them with a flag. For a manually minified file you lose this, which is fine for a 2 KB script and painful for an app. Rule of thumb: minify by hand for small standalone assets; use a build tool for anything larger.
Where minification fits in a workflow
- WordPress: caching and optimisation plugins minify and combine on the fly. This is convenient and occasionally breaks a theme; if a site looks wrong after enabling minification, exclude the offending file rather than turning it all off.
- Static and custom sites: minify in the build step so the source stays readable and the deployed files are small.
- One-off assets (an inline script in a landing page, a custom CSS block in a page builder): paste into the minifier, paste the result back. Keep the readable version in a file somewhere.
- Reverse direction: when you inherit minified code with no source, the HTML, CSS & JavaScript Formatter re-indents it. Names stay short but structure becomes readable.
What minification won’t fix
If a page loads 40 scripts, minifying each one saves a few kilobytes per file and none of the 40 requests. The bigger wins are usually removing unused CSS (page builders ship far more than a page needs), deferring non-critical JavaScript, and combining files where HTTP/1.1 is still in play. Minify last, after those.
Frequently asked questions
Does minification improve page speed?
Yes, modestly: smaller files download and parse faster. The effect is largest on JavaScript and on sites without compression enabled.
Is minified code obfuscated?
Slightly harder to read, but not protected. Anyone can format it back. Obfuscation is a separate, deliberate step and rarely worth it.
Should I minify HTML?
The gains are small (HTML compresses well and is usually small anyway) and the risks around <pre> and inline whitespace are real. Do it only if a build tool handles it safely.
Can I un-minify a file?
You can re-indent it with a formatter. Renamed variables and removed comments cannot be recovered without a source map.
Free, runs in your browser, nothing uploaded, no sign-up.
Keep reading
More from Developer & Code Tools.



Tools for this job
Free, in your browser, no sign-up.