View contents
Text Compression: Why Compressing Resources Is Essential for Web Performance
Introduction
Text compression is one of the most effective ways to reduce file sizes and improve page load times. By compressing text-based resources (HTML, CSS, JavaScript, JSON, XML), you can reduce transfer sizes by 60-90%, directly improving TTFB, FCP, and overall page speed.
Most modern web servers and CDNs support compression, but many sites still serve uncompressed resources—leaving significant performance gains on the table.
How Text Compression Works
When a browser requests a resource, it tells the server which compression formats it supports via the Accept-Encoding header. The server then compresses the response and indicates the compression method in the Content-Encoding header.
Request/Response Flow:
┌─────────────────────────────────────────────────────────────┐
│ 1. Browser sends request: │
│ GET /styles.css HTTP/1.1 │
│ Accept-Encoding: gzip, deflate, br │
│ │
│ 2. Server compresses and responds: │
│ HTTP/1.1 200 OK │
│ Content-Encoding: br │
│ Content-Length: 12540 (compressed) │
│ [Brotli-compressed CSS content] │
│ │
│ 3. Browser decompresses and uses: │
│ Original: 85 KB → Compressed: 12 KB (86% smaller!) │
└─────────────────────────────────────────────────────────────┘
Common Compression Algorithms
Gzip
The most widely supported compression format. Available on virtually all servers and supported by all browsers since the early 2000s.
| Aspect | Details |
|---|---|
| Browser Support | 100% (all browsers) |
| Compression Ratio | 60-80% reduction |
| CPU Cost | Low to moderate |
| Best For | Universal fallback |
Brotli
A newer compression algorithm developed by Google, offering 15-25% better compression than gzip with similar decompression speeds.
| Aspect | Details |
|---|---|
| Browser Support | 97%+ (all modern browsers) |
| Compression Ratio | 70-90% reduction |
| CPU Cost | Higher compression, similar decompression |
| Best For | Static assets, HTTPS traffic |
Deflate
An older algorithm that gzip is based on. Rarely used directly today.
| Aspect | Details |
|---|---|
| Browser Support | Universal |
| Compression Ratio | Similar to gzip |
| Best For | Legacy systems only |
What Should Be Compressed?
Compress These (Text-Based Resources)
| Resource Type | Typical Savings | Notes |
|---|---|---|
| HTML | 60-80% | Always compress |
| CSS | 70-85% | Very compressible |
| JavaScript | 60-80% | Significant savings |
| JSON/XML | 70-90% | API responses benefit greatly |
| SVG | 50-70% | Text-based vector graphics |
| Plain text | 60-80% | Logs, feeds, etc. |
Don’t Compress These (Already Compressed)
| Resource Type | Why Not |
|---|---|
| Images (JPEG, PNG, WebP) | Already compressed; may increase size |
| Videos (MP4, WebM) | Already compressed |
| Fonts (WOFF2) | Already compressed |
| ZIP/PDF | Already compressed |
Impact on Performance Metrics
Text compression improves multiple performance metrics:
| Metric | How Compression Helps |
|---|---|
| TTFB | Server can send smaller response faster |
| FCP | Critical CSS/JS arrives sooner |
| LCP | Faster HTML delivery improves LCP |
| Speed Index | Overall visual progress improves |
| Total Blocking Time | Less JavaScript to parse |
Real-World Savings Example
Before Compression:
├── index.html: 45 KB
├── styles.css: 120 KB
├── app.js: 350 KB
├── vendor.js: 280 KB
└── Total: 795 KB
After Brotli Compression:
├── index.html: 9 KB (80% smaller)
├── styles.css: 18 KB (85% smaller)
├── app.js: 85 KB (76% smaller)
├── vendor.js: 72 KB (74% smaller)
└── Total: 184 KB (77% smaller!)
Time Savings on 3G: ~5.5 seconds faster
Common Compression Problems
Problem 1: No Compression Enabled
Issue: Server serves files without any compression.
Solution: Enable gzip or Brotli in your web server configuration.
Problem 2: Compressing Already-Compressed Files
Issue: Server tries to compress images or WOFF2 fonts, wasting CPU.
Solution: Configure server to only compress text-based MIME types.
Problem 3: Gzip Only (No Brotli)
Issue: Missing out on 15-25% additional savings from Brotli.
Solution: Enable Brotli for HTTPS traffic with gzip fallback.
Problem 4: Low Compression Level
Issue: Using fastest compression setting for static assets.
Solution: Use higher compression levels for pre-compressed static files.
Checking Your Compression
Using Browser DevTools
- Open DevTools → Network tab
- Click on any text resource (HTML, CSS, JS)
- Check Response Headers for
Content-Encoding - Compare “Size” vs “Transferred” columns
Using Lighthouse
Run a Lighthouse audit and look for:
- “Enable text compression” - Lists resources that could be compressed
- Shows estimated savings in KB and time
Using curl
# Check if compression is enabled
curl -I -H "Accept-Encoding: gzip, br" https://example.com
# Look for: Content-Encoding: gzip (or br)
Related Articles
Learn more about optimizing resource delivery:
- TTFB Optimization Guide - Compression directly improves TTFB
- Render-Blocking Resources Explained - Compress critical resources
- Font Loading Explained - Font compression formats
📚 Back to Performance SEO Hub - Explore all performance topics
References
- MDN Web Docs - Content-Encoding
- web.dev - Minify and Compress Network Payloads
- Chrome Developers - Enable Text Compression
Try It Yourself
Want to check if your site uses compression?
🔧 Download UXR SEO Analyzer (Free, 100% local analysis)
Disclaimer: The analyzers in this extension are reference guides based on official documentation from MDN, web.dev, and Chrome Developers. They do not represent absolute truths about how search engines evaluate your content—only search engines know their internal algorithms. Use these recommendations as a starting point to improve your site.
Last updated: December 15, 2025