Expires Header

One of the many Firefox plug-ins I use is YSlow. It performs several measurements on a web page and gives performance improvements. One of the suggestions is the Expires header. By using the expires header, the components, such as images, javascript, flash, and css files, become cacheable. In other words, on items that rarely change.

Once downloaded, the browser figures out if the component needs to be refreshed; if not, it does not ask for it from the server. This process saves a lot of traffic to and from the server, especially if there are a lot of static components.

Originally designed for images, it is suggested that css, flash, and javascript files use it, too.

How to Set the Expires Header

Note this works only for Apache servers

In the .htaccess file add the following code (either method 1 or 2).

Method 1

The expires header is in the mod_expires.c module on the Apache server.

ExpiresActive On - turns on the expires header.

The ExpiresByType has the MIME definition after it then the time of delay. Note that image/jpeg handles jpeg, jpg extensions.

The number following A is the #of seconds
Also i got the meaning of A2592000 = 720hours = 30days
the numbers after A is the time to expire time (in seconds)
ie A3600 is 1 hour

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType image/png A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/x-icon A2592000
</IfModule>

Method 2

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 2 days"
ExpiresByType image/gif "access plus 60 days"
ExpiresByType image/jpeg "access plus 60 days"
ExpiresByType image/png "access plus 60 days"
ExpiresByType application/x-javascript "access plus 60 days"
ExpiresByType text/css "access plus 60 days"
ExpiresByType image/x-icon "access plus 360 days"
</IfModule>

If you need to change a static file change the name of it so it is read in by the browsers.