Image and resource caching with htaccess

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, to change the time the resource is cahced for just change the “max-age” parameter, it’s value is seconds. The link posted above has loads more info.

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>