1) mod_gzip / mod_deflate! This is such an easy solution. I am surprised that it is not enabled by default.
2) Play with tricks with your URL so you can convince browsers to cache your JS and CSS files forever. In other words, create a URL that looks like this:
http:
Then use mod_rewrite and cross out "-v123":
<IfModule mod_rewrite.c>
Now apache will look for "/js/mad_scriptz.js" ... Each time you change static content, just increase the version number to force browsers to reload the content. Usually I have a template variable containing the global version number to which everything is bound. Not the most effective, but it works for my purposes. If you can link the version number to your build system or file hash, that would be really nice.
Get mod_expires, so all your static things expire in a few years:
<IfModule mod_expires.c> ExpiresActive On # all in seconds... ExpiresByType image/x-icon A2592000 ExpiresByType image/gif A2592000 ExpiresByType image/jpeg A2592000 ExpiresByType image/png A2592000 ExpiresByType application/javascript A2592000 ExpiresByType application/x-javascript A2592000 ExpiresByType application/x-shockwave-flash A2592000 ExpiresByType application/pdf A2592000 ExpiresByType text/css A2592000 ExpiresByType application/rdf+xml A1800 </IfModule>
Update: It has been noted that not all browsers or search engines like gzip'd. Do not blindly turn it on, as I suggest above. Make sure you don't download gzip antivirus browsers even if they accept it (some of them will get pissy with javascript compressed). The documentation for mod_gzip and mod_deflate both have examples that should work fine (I assume they do this, or people would email them with the changes :-).
I should also mention that my experience is that if you have a reverse proxy between Apache servers and mod_gzip'd servers, you need to follow. Squid 2.6 often tricks Apache, rather than gziping, when it should and worse, it caches uncompressed versions and passes them to browsers that can handle gzip'd content. Dunno, if 3.0 fixes this, and I don’t know, there is something wrong with my configuration (doubt it). Just watch out for :-)
That said. Turn it on. Seriously: -)
Cory R. king
source share