Minification or compression — the difference, and why you need both

"I already minified the files, why do I need compression on the server too?" — probably the most common question about site speed. And it rests on a false premise: that these are two ways of doing the same thing, and you pick one.
They aren't. They're two different stages, happening at different times in different places — and together they give you more than either alone. Let's take them in order.
Minification: it rewrites your code
Minification happens at build time, on your machine or in CI. A tool reads the code and rewrites it to do exactly the same thing in less space:
- strips comments and whitespace,
- shortens variable and function names to one or two letters,
- drops code that provably never runs.
The output is a file a human can't read and a browser doesn't care about. That's exactly why DevTools has a pretty-print button: put the line breaks back so you can make something out.
The important bit: the result of minification is a new file on disk. It stays that way, and that's what gets served.
Compression: it packs the bytes in transit
Compression happens during transfer, on the server. The file on disk doesn't change — only the copy travelling the network gets packed.
The browser and server negotiate this themselves. On every request the browser states which algorithms it understands, the server picks one, compresses the response body, and reports which one in the content-encoding header. The browser unpacks it and carries on — your code never knows any of this happened.
Two algorithms matter today: good old gzip and the newer brotli (spelled br in headers). Brotli is understood by browsers covering roughly 97% of users.
The win here is large because of the nature of text: ordinary text carries up to 60% redundancy, and size reductions reach 70%.
The comparison that matters
- What it does. Minification changes the code itself. Compression doesn't change a byte of meaning — it just packs what's there.
- When it happens. Minification once, at build. Compression on every delivery (or once, if the server caches the compressed copy).
- Who configures it. Minification is the bundler's job and is normally already on in production mode. Compression is the server's or host's job, often a single toggle.
- What you can see from outside. Minification is visible in the page source: the code is unreadable. Compression isn't visible in the source at all — only in the response header.
- If you enable only this one. Minification without compression leaves you shipping full-size text over the wire. Compression without minification faithfully compresses your comments and long names too — for nothing.
Why together you get more than the sum
Here's the non-obvious part, and the reason to keep both stages.
Compression algorithms make their money on repetition: the more often the same sequence of characters shows up, the shorter it can be encoded. Minification increases the amount of repetition. When twenty different long variable names all become a, b, c, the text gets more uniform — and packs tighter.
So minification doesn't merely take its own slice first. It makes compression's work more effective.
Which one when
"Enable both" is correct but useless. More concretely:
Minification — always, and you probably already have it. Vite, webpack and Next.js minify on production builds by default. There's nothing to configure; to check, open a built file — if it's one long line, it's working. Don't disable it for "readability in production": that's what source maps are for.
Compression — also always, but verify it's on. On managed platforms and behind a CDN it's usually there out of the box. On your own server you have to switch it on by hand, and this is where the cheapest win most often goes missing.
Brotli or gzip? For static files, brotli: it packs harder, and it only packs once — at build or first delivery, after which the result is cached. For responses generated on the fly and never cached, brotli can be the wrong call: it compresses slower than gzip, and the CPU time eats the byte savings. A sane setup is brotli for files, gzip for dynamic responses.
Don't re-compress images and video. JPEG, WebP and MP4 are already compressed internally. A second pass gains nothing and can make the file bigger — the bookkeeping outweighs the saving.
How to check your own numbers step by step is in the guide on how to shrink your JavaScript bundle.
How do I tell whether compression is on at all?
Open DevTools, the Network tab, click any JS or CSS file and look for content-encoding in the response headers. A value of br or gzip means you're fine. No header means the file travels at full size.
Can minification break my code?
Practically never; modern tools are reliable. What does break is code that depends on function names at runtime — for example, looking something up by a class name string. Those spots need to be marked explicitly.
What does minifying HTML and CSS get me?
Less than with JavaScript: there's nothing to rename, so it mostly strips whitespace and comments. But it's free and certainly doesn't hurt.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





