1
votes

Should a response with a Cache-Control header with a max age for some point in the future send a conditional request the next time the resource is required?

For example I've set the server to return a Cache-Control header to expire in 10 days and sure enough the first response for the resource from the server is Http Status: 200 with a Cache-Control max-age=864000 header. However the second time the resource is required another request is made and this time a Http Status: 304 is returned. Both times the Last-Modified header is some date in the past.

The fact that I get 304 status is not suprising after all the resource hasn't changed and the cache version is then used. However should the request, which clearly is a conditional one, be made in the first place? I was under the impression that if the max age of the cache control header had not been exceeded then the browser should not even make the request and instead should just use the cache version of the resource.

I first thought this was an IE9 browser issue as this was the browser that I was testing it in and after a little googling I found the following article on caching improvements in IE9. The article confirms what I was thinking in that no request should be made for cached resource that aren't stale:

If the browser later needs a resource which is in the local cache, that resource’s headers are checked to determine if the cached copy is still fresh. If the cached copy is fresh, then no network request is made and the client simply reuses the resource from the cache.

If a cached response is stale (older than its max-age or past the Expires date), then the client will make a conditional request to the server to determine whether the previously cached response is still valid and should be reused. The conditional request contains an If-Modified-Since and/or If-None-Match header that indicates to the server what version of the content the browser cache already contains. The server can indicate that the client’s version is still fresh by returning HTTP/304 Not Modified headers with no body, or it can indicate that the client’s version is obsolete by returning a HTTP/200 OK response with the new version of the content.

I also checked the Internet Options for IE and double checked the Check for newer versions of stored pages option was set to Automatically which should let the browser decide when to make a request for a resource.

For good measure I also tested this in Firefox and Chrome and found that this not an IE9 problem as both these browsers responded in the same way as IE9 and sent conditional responses.

Is this normal behaviour should a conditional request be sent for a cached item that is not stale?

1

1 Answers

2
votes

You are right. Under normal circumstances, no conditional requests should be issued if the cache is still valid. This means that there's something else going on that's making the browser go and check for the cache. Read on:

There are a number of reasons why IE might make a conditional request for an item that is already in the cache:

  • The cached item is no longer fresh according to Cache-Control or Expires
  • The cached item was delivered with a VARY header
  • The containing page was navigated to via META REFRESH
  • JavaScript in the page called reload on the location object, passing TRUE for bReloadSource
  • The request was for a cross-host HTTPS resource on browser startup
  • The user refreshed the page

So you'll have to do a little digging to find out what's going on. You can get more information in the following link: http://blogs.msdn.com/b/ieinternals/archive/2010/07/08/technical-information-about-conditional-http-requests-and-the-refresh-button.aspx