my latest
Rambling: 323 days of failure - read it
Fri 19th Nov
Tweet: kevbaldwyn: 6 hour ferry ride on the slowest boat in the Maldives and 3 hours later I still feel like I'm on a boat.
Wed 15th Feb
Code: Image and resource caching with htaccess - read it
Wed 23rd Mar
my photos
Hassan II Mosque, Wide Angle - Casblanca
Hassan II Mosque, Front - Casblanca
Hassan II Mosque, Polarised - Casblanca
Hassan II Mosque - Casblanca
Casablanca
The magical world of Disney
The Disney Castle
Snowy Branch
 

Image and resource caching with htaccess

Wednesday 23rd March '11

This is as much a bookmark for myself as anything. I just discovered this .htaccess trick to easily set resource caching with apache. It requires mod_headers enabled which comes compiled by default but switched off. Then all you need do is add something like this to your .htaccess file:

<IfModule mod_headers.c>
	<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf)$">
	Header set Cache-Control "max-age=2592000"
	</FilesMatch>
</IfModule>

Which will cache images and flash for one month. The link posted above has loads more info.

Post a comment

Dave   30th Mar 2011
Dude, you know that you'll need a caching server (varnish) if you want the server to do some caching - you can get varnish to honor the header files and take the load off Apache.... great for serving up images (most Apache instances are over 10Mb of memory it loads up all the bloated modules even if its just serving up an image)