Menu:

While admins and webmasters use HTTP headers such as Last-Modified to influence how browsers and proxy caches cache their content, many are unaware of how caching logic functions "under the hood", and as a result, many are unaware of a secret weapon in the webmasters toolbox: the Expires header.

When returning content, be it static (files) or dynamic, it is usually easy for the programmer to determine when the content was last modified, and report this back to the HTTP client via the Last-Modified header.

However, consider the "question" that each browser and caching proxy must ask itself, before requesting a page: Has this content changed since the last time I requested it from the server?

It should obvious that the answer to this question cannot be obtained from a last-modified timestamp. Such a timestamp tells us nothing about when the content will be next modified. This is usually impossible: one cannot predict the future. A last-modified time is merely a useful guide, enabling If-Modified-Since conditional queries.

Normally, browsers employ some additional hueristics, such that, they avoid re-requesting content during the same session. Outside of that, a server round-trip is required to verify that the content has not changed.

Contrast this with use of the Expired header: This header informs a browser or proxy cache that content is highly unlikely to change before the expiration date.

Intelligent use of Expires for static content, and content that changes infrequently, can reduce server round-trips, and as a result, reduce bandwidth usage and speed website performance. Your website will load faster between user browser sessions.

Don't set the Expires date too far into the future. As with everything else in life, a good value is a balance of many factors. You want to cache as much as possible, while still ensuring that it doesn't take months for changes to your website to propagate to the Internet. Experiment with Last-Modified, Expires and Cache-Control headers for the combination that suits each content class (static images, current content, archived content, etc.) at your website.

Although it might seem counter-intuitive, content that changes frequently may benefit from this technique as well. Expires usually functions in a manner similar to DNS TTL's. You can use Expires to ensure that clients do not revalidate their content more often than (for example) once every 30 seconds.