Chapter 3

Content Compression


  • Understanding how HTTP compression works
  • Becoming familiar with browser quirks and how to handle clients that don’t support compression
  • Exploring alternatives to gzip and deflate compression
  • Compressing directly in PHP

With bandwidth being a bottleneck for many users (and for dial-up users, easily the largest bottleneck), it’s not surprising that web masters would want to compress their content. The benefits are obvious — faster loading times for users and reduced data transfer bills for web masters. This chapter examines the available methods of compression, which browsers support them, and situations in which compression is not appropriate.


Armed with a list of the 1,000 most popular websites (courtesy of, a quick test of average page sizes and compression support revealed how the top 20 rate, as shown in Table 3-1.

TABLE 3-1: Average Page Sizes of the Top 20 Websites


As you can see, compression is well supported. Of the top 1,000 sites, 227 did not support compression, with only 1 in the top 20 ( and 10 in the top 100 not supporting it.

There’s also a fairly wide range in the amount of compression achieved in this Top 20 table, with the size of the compressed contents being anything between 15 percent and 60 percent of the original. In general, you should expect to see a compression ...

Get Professional Website Performance: Optimizing the Front-End and Back-End now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.