Expires in the Past no Expires Expires in the Future

This page tests how XHR requests are cached. This issue was initially discussed in a HttpWatch blog post. In that post, it was mentioned that:

...any Ajax derived content in IE is never updated before its expiration date - even if you use a forced refresh (Ctrl+F5). The only way to ensure you get an update is to manually remove the content from the cache.

This is surprisingly true. This test page explores this a bit more. This page contains an image, an external script, and an XMLHttpRequest. The expiration time varies depending on which link you select above.

Table 1. When XHR is cached, what happens when you hit F5?
  Past Expires No Expires Future Expires
Chrome 2 304 304 304
Firefox 3.5 304 304 304
IE 7 304 cache cache
IE 8 304 cache cache
Opera 10 304 cache 304
Safari 4 200 200 200

Table 1 shows the results of testing this page on major browsers. The test was to click on a link (e.g., Expires in the Past) and then hit F5. The result recorded in the table is whether the XHR was re-requested or read from cache, and if it was re-requested what was the HTTP status code. Here's what happens when F5 is hit:

Takeaways

  1. Developers should either set a past or future expiration date on their XHRs, and avoid the ambiguity and variant behavior when no expiration is specified.
  2. If XHR responses should not be cached, developers should assign them an expiration date in the past.
  3. If XHR responses should be cached, developers should assign them an expiration date in the future. When testing in IE 7&8, developers have to remember to clear their cache when testing the behavior of Reload (F5).
  4. Opera and Safari should stop re-requesting favicon.ico when F5 is hit.
  5. Safari should send If-Modified-Since when F5 is hit.