elefcode
← All guides

Web & APIs · 4 min read

Minification vs Compression

Minification and compression both make files smaller, so they get conflated — but they work at different stages and stack together. Using both is standard practice.

This guide explains the difference and what each buys you.

Try it yourself with the related tool.

Beautify or minify code →

Advertisement

Minification changes the file

Minification rewrites your source into an equivalent but smaller form: it strips comments and whitespace, and for JavaScript it can also rename local variables to single letters and drop unreachable code. The result is a different file that behaves identically. It happens once, at build time.

Compression changes the transfer

Compression (gzip or Brotli) does not change your file at all — the server compresses the bytes when sending them and the browser decompresses on arrival. It is transparent, happens per request, and applies to whatever you serve, minified or not.

Why use both

They compound. Minification removes redundancy that compression cannot infer (like long variable names), and compression then squeezes the remaining repetition in the byte stream. Minifying first typically gives compression a smaller, more repetitive input to work with, so the final transfer is smaller than either technique alone.

Practical notes

Enable Brotli or gzip at your server or CDN — on most modern hosts this is on by default. Minify as part of your build with a tool like esbuild or terser, and ship source maps so production stack traces stay debuggable. Do not minify by hand: the whole point is that a build step does it reliably.

Related guides