Course contentsShow
← Web Development
Lesson 2131 of 2,98239. Network PerformanceFree lesson

Understanding HTTP Compression Basics

Learn how compression reduces file sizes, why it matters for performance, and how browsers and servers negotiate compression.

Understanding HTTP Compression Basics

What you'll learn: How compression shrinks file sizes for faster network transfer and how browsers and servers automatically negotiate it.

What Is HTTP Compression?

HTTP compression is like vacuum-sealing your luggage before a flight—it squeezes files to make them smaller for transit, then unpacks them at their destination. When you request a webpage, the server can compress text files (HTML, CSS, JavaScript, JSON) before sending them over the network, dramatically reducing transfer time.

Why Compression Matters for Performance

Network transfer is often the biggest bottleneck in web performance. A 500 KB JavaScript file might compress down to 100 KB, meaning it downloads 5× faster. This is especially critical for users on mobile networks or slower connections. Compression directly reduces:

  • Download time
  • Bandwidth costs
  • Time to Interactive metrics
  • Data usage for mobile users

How Browser-Server Negotiation Works

The process happens automatically through HTTP headers:

  1. Browser advertises support: The browser sends an Accept-Encoding header listing compression algorithms it understands (e.g., gzip, br for Brotli, deflate)
  2. Server compresses response: If configured, the server compresses the file using one of the supported algorithms
  3. Server signals compression: The response includes a Content-Encoding header indicating which algorithm was used
  4. Browser decompresses: The browser automatically decompresses the file before using it

The entire process is invisible to your JavaScript code—it happens at the HTTP layer.

Common Compression Algorithms

  • gzip: Widely supported, good compression ratios
  • Brotli (br): Modern algorithm with better compression than gzip, especially for text files
  • deflate: Older, less common

Browsers decompress files so quickly that the CPU cost is negligible compared to network savings.

Key Takeaway: HTTP compression automatically reduces file sizes by 60-80% for text-based resources through transparent browser-server negotiation, making it one of the easiest performance wins available.