What to Compress
Servers choose what to gzip based on file type, but are typically too limited in what they are configured to compress. Many web sites gzip their HTML documents. It's also worthwhile to gzip your scripts and stylesheets, but many web sites miss this opportunity (in fact, it's worthwhile to compress any text response including XML and JSON, but the focus here is on scripts and stylesheets since they're the most prevalent). Image and PDF files should not be gzipped because they are already compressed. Trying to gzip them not only wastes CPU resources, it can also potentially increase file sizes.
There is a cost to gzipping: it takes additional CPU cycles on the
server to carry out the compression and on the client to decompress the
gzipped file. To determine whether the benefits outweigh the costs you
would have to consider the size of the response, the bandwidth of the
connection, and the Internet distance between the client and the server.
This information isn't generally available, and even if it were, there
would be too many variables to take into consideration. Generally, it's
worth gzipping any file greater than 1 or 2K. The mod_gzip_minimum_file_size directive controls
the minimum file size you're willing to compress. The default value is
500 bytes.
I looked at the use of gzip on 10 of the most popular U.S. web sites. Nine sites gzipped their HTML documents, seven sites gzipped most of their scripts and stylesheets, and only five gzipped all of their scripts and ...