HTML and CSS Reference
In-Depth Information
If you want to precisely specify when the cached copy should expire, you can send an Expires header instead of
or in addition to the Last-modified header. The value of the Expires header is a date in the future after which
the cache should be flushed and a new copy loaded. For example, this header sets the expiry time for
Wednesday, August 8, 2012:
Expires: Wed, 08 Aug 2012 09:41:05 GMT
This is much longer than most browsers will hold on to a document by default. You might choose such a long
time for static images that are very unlikely to change. You can also try setting an Expires header in the
relatively distant future for each separate embedded component on a page: scripts, stylesheets, Flash
animations, and the like. In Apache, you can do this by setting the ExpiresDefault property in your .htconfig
file like so:
ExpiresDefault "access plus 2 weeks"
The downside of this is that many surfers will continue to use the cached components until the time period
expires. To get around this, when you change one of them, also change its name. Sometimes it's helpful to just
add a version number to each such resource: stylesheet_111.css, stylesheet_112.css, and so forth.
You can use the ExpiresByType directive to override the expiry time for particular types of documents. For
instance, if the HTML files change frequently, you may want them to expire very quickly. This sets them to
expire after 3,600 seconds:
ExpiresByType text/html M3600 # HTML expires after one hour
You can use the Cache-control header to specify a relative expiry time. For example, this header sets the expiry
time one hour (3,600 seconds) after the client has first retrieved the page:
Cache-Control: max-age=3600
Search WWH ::

Custom Search