0
votes

I have a static image which will expire in 9 minutes. It has following headers set by the server:

Cache-control: max0age=523 Expires: Thu, 27 Aug 2015 23:28:14 GMT (in 5 minutes) Last-Modified:Wed, 12 Nov 2014 08:06:06 GMT

When I refresh the page browser makes request to server instead of serving it from the cache. As expected it gets 304 from server. Screenshot from Chrome dev tools below: enter image description here

I compared it with resource cached with same headers (max-age and last-modified) and seeing that content gets served directly from cache:

enter image description here

So basically I have two questions:

  1. Why Chrome does not serve image from cache and validates it against server?
  2. Why same not applies to my second example with js file from Bing.com and it served directly from cache? Is it because "public" specified in cache-control or aggressive expiration date?

Some clarifications:

  1. I'm refreshing the page in both examples.
  2. I am not doing hard refresh (Crtl+R or Ctrl+F5).
  3. It is not because of dev tools opened, I tried to close dev tools and I'm seeing same in Fiddler.
1

1 Answers

0
votes

Your browser is sending a Cache-Control: max-age=0 header. That's means your browser is deliberately bypassing the cache when you refresh.

  • If navigate to the page normally instead of refreshing, it should load the image from the cache.
  • If you hold Shift when you click Refresh, you'll force a hard refresh, which additionally won't since an If-Modified-Since header. You'll get a 200 instead of a 304, without any caching.