Reputation: 3708
Apache 2.2.17 PHP 5.3.3
Currently, my app doesn't use gzip, but I would like it to. However, I'm not sure of a few things:
Essentially, if you've implemented gzip on a mature site, and run into problems, I'd love to know what those were, and what you did to work-around these problems. Thanks!
Upvotes: 3
Views: 662
Reputation: 15945
Other than bmp's (if you see someone using them over the wire, prepare your shotgun), images are mostly already compressed, including jpeg's, png's and gif's.
I use this in my static subdomains, compiled from some online resources (which can be found easily Googling):
# Insert filter
<FilesMatch "(?i)^.*\.(js|css|html?|php3?|xml|txt)$">
SetOutputFilter DEFLATE
</FilesMatch>
# *.cache.js and *.cache.css files are only checked after 6 month (e.g. jQuery.1.4.2.cache.js)
<FilesMatch "(?i)^.*\.(cache)\.(js|css)$">
FileETag None
ExpiresActive On
ExpiresDefault "access plus 6 month"
</FilesMatch>
#AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
#SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
The only special thing I've added is that I cache *.cache.js and *.cache.css files for 6 months, since they rarely change. E.g. jqueryui.cache.css
Upvotes: 1
Reputation: 25139
Nothing else to be said
Do it in Apache, it is easy to set up and requires no change to your code. You can also set it up easily to compress css and js files if you want.
Apache can be set to compress only specific file types
Compressing an already compressed file will almost always result in a larger file. If you have uncompressed images, like bmps, you will get better results using a compression technique specific to images than using gzip, so you are better off just converting them to gif, png, jpg depending on your needs.
I am not sure about streaming, but the same as images applies to audio. If it is already compressed, don't compress it again, and if it is not, use a compression technique specific to the type.
Basically, gzip is great for compressing text files so I would set Apache to compress those. For anything else, there are better solutions if you need it.
Upvotes: 5