I’ve written about the Yahoo and Google tools available for helping you find ways to speed up your site. There are lots of good suggestions that are easy to understand, but there’s one that isn’t so well known.
If you are getting an warning about The following resources are missing a cache expiration, here’s what that means, and how to fix it.
What that means is that those resources (images, javascript calls, css files) are missing a cache expiration. Resources that do not specify an expiration may not be cached by browsers. Caching improves performance by transparently storing data on your computer so that future requests for that data can be served faster than requesting it from the server.
You can modify your .htaccess file to make sure that the right type of things get cached on your site.
Here’s what I usually use:
ExpiresActive On
#Add Cache-Control Headers
Header set Cache-Control "max-age=3153600, public"
#Add Cache-Control Headers
Header set Cache-Control "max-age=86400, public, must-revalidate"
#Add Cache-Control Headers
Header set Cache-Control "max-age=3600, must-revalidate"
Adding the above to your .htaccess file tells visiting browsers that if they request an icon, pdf, image, javascript, stylesheet or flash resource to store a temporary version of it for 60 days (5,184,000 seconds). That way, if it is need again it can be accessed quickly. The reason we can do that is because those files rarely (if ever) change.
In the next block, xml and txt live slightly shorter before having to be requested again, and finally html files only live for an hour before needing to be requested.
Putting the code inside of the <IfModule mod_expires.c> tag allows you to trap and test if mod_expires.c is included in your Apache build. If you try to insert the code and mod_expires.c isn’t included, you’ll usually see a 500 error displayed.
Speed of Light photo by John Talbot via Flickr
Leave a Reply