What to Compress and What Not to Compress
You'll learn which file types truly benefit from compression and which ones waste server CPU cycles because they're already compressed.
The Core Idea
Not all files should be compressed with Gzip or Brotli. Some file types are already compressed by their own format, and running them through additional compression won't make them smaller—it just burns CPU time on your server and the user's device for zero gain.
Think of it like trying to vacuum-seal an item that's already shrink-wrapped. You're adding extra work without making it any more compact.
Files That Should Be Compressed
Text-based formats are highly compressible because they contain lots of repetition and patterns:
- HTML files (
.html) - CSS stylesheets (
.css) - JavaScript files (
.js) - JSON data (
.json) - XML files (
.xml) - SVG images (
.svg) — they're XML-based text - Plain text (
.txt) - Web fonts in uncompressed formats
These can shrink by 60-90% with Gzip or Brotli compression.
Files That Should NOT Be Compressed
Already-compressed formats gain nothing (or almost nothing) from additional compression:
- Images: JPEG (
.jpg), PNG (.png), WebP, GIF - Videos: MP4, WebM, AVI
- Audio: MP3, AAC, OGG
- Compressed archives: ZIP, GZIP, RAR
- Already-compressed fonts: WOFF, WOFF2
These formats use their own compression algorithms internally. Applying Gzip or Brotli typically results in files that are the same size or even slightly larger due to compression overhead.
The CPU Trade-off
Compression isn't free—it requires CPU cycles on both ends. Only compress files where the bandwidth savings justify the computational cost. A 500-byte already-compressed image? Skip it. A 50KB CSS file? Definitely compress it.
Key Takeaway: Compress text-based assets (HTML, CSS, JS, JSON, SVG) but skip pre-compressed formats (images, videos, audio, WOFF2) to maximize bandwidth savings without wasting CPU resources.