As part of my efforts to improve the performance www.epiphanyrisknetwork.com, I wanted to set Expires headers on components so that they become cacheable and avoid unnecessary HTTP requests on subsequent page views. (Ref: http://developer.yahoo.com/performance/rules.html#expires)
I’ll be improving this over time, but so far I have the following in my .htaccess file:
<IfModule mod_expires.c> ExpiresActive on ExpiresByType image/gif "access plus 1 months" ExpiresByType image/png "access plus 1 months" ExpiresByType image/jpeg "access plus 1 months" ExpiresByType image/ico "access plus 1 months" ExpiresDefault "access plus 1 days" </IfModule>
Let’s break this down…
ExpiresActive on
The first directive simply informs that the module should be used.
ExpiresByType image/gif "access plus 1 months" ExpiresByType image/png "access plus 1 months" ExpiresByType image/jpeg "access plus 1 months" ExpiresByType image/ico "access plus 1 months"
The second through to fifth directives deals with specific image types. So the first of these informs that GIFs should be reloaded from the web server one month after the document was last accessed.
ExpiresDefault "access plus 1 days"
The sixth and final directive informs that all document types that are not specified should be reloaded one day from the current time.
The time parameters in the quotes may be access (A) or modification (M). Setting now is also valid, this is the same as access. Setting A or access produces the same result. It is preferrable to use access over modification because modification only can be applied to files that come from disk, apache does not figure out modification time for other objects and omits the header in these cases.
The plus key is not needed and is only optional to make the configuration files easier to read.
The time length is specified in seconds by default, or any of the following keys can be used:
- years
- months
- weeks
- days
- hours
- minutes
- seconds
So:
ExpiresDefault "access plus 2 minutes"
is equal to setting the slightly more cryptic:
ExpiresDefault "A120"
