Apache, gzip compression and binary files
We've set up Apache to deflate most web content it serves with gzip, to make file transmission faster with smaller file sizes. This is great for HTML files, CSS and JS files, but for binary files, such as images and media files, or PDFs it can cause problems.
For PDFs the problems are that Acrobat can't read PDFs that have been gzipped, so it must be turned off for them.
Images generally are compressed already so there's no point i.e. it just consumes CPU power pointlessly, and it may also cause problems with clients (such as browsers) not knowing the size of the file to display.
Media files are sent with "Transfer encoding: chunked" set in the header and no "Content length" entry in the headers. This is because Apache can't work out how large the files are once they have been compressed, so it send them chunked. Various players can't handle chunked data so they play the first chunk or few chunks, assuming that to be the entire file.
The following code sets up compression but not for the content types above. It should be added to /etc/httpd/conf/httpd.conf.
<Location /> SetOutputFilter DEFLATE SetEnvIfNoCase Request_URI \ \.(?:gif|jpe?g|png)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \ \.(?:mp3|wav|wma|au|m4p|snd|mid|wmv|mpg|mpeg|mp4|qt|mov)$ no-gzip dont-vary SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary SetEnvIfNoCase Request_URI \ \.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary </Location>