0

I have set Cache-Control=max-age=315569520 & Expires to 10years from now.

Still browser is not reading the file from cache & making GET request to S3. In response 304 is received but my S3 GET count is increasing because of this.

Please suggest correct way to set cache for S3 files

Lajpat
  • 591
  • 5
  • 19
  • `Expires` is deprecated and unnecessary. Try without it... and then try a more reasonable value for `Cache-Control: max-age=...` such as 86400, just to see if perhaps the browser is discarding the value as though it were too large to be considered correct. Also, mention browser and version so others can try to replicate the behavior you are seeing. – Michael - sqlbot Nov 15 '16 at 13:04
  • Michael your suggestion is not working. I tried this on latest Chrome, Opera & Safari. It is working perfectly on Firefox. Is it got to do with Cache-Control=0 in Request header in Chrome & Cache=No in Safari? – Lajpat Nov 15 '16 at 13:34
  • Verify that this isn't an artifact of your test methodology. Browser behavior is something of a moving target, but [this answer](http://stackoverflow.com/a/3934694/1695906) may give some insight into when the browser may send `If-Modified-Since` requests for cached content (first touch during a browser session? reload?), and when it won't. In my estimation, this is not, fundamentally, an S3-specific question at this point, but rather one of browser behavior, and given an identical response from a server other than S3, the browser behavior should also be identical. – Michael - sqlbot Nov 15 '16 at 13:57

1 Answers1

0

When the img resource is requested via address bar, Chrome & Opera sends Cache-Control=0 in Request header & Safari send Cache=No. Because of this browser does not pick up images from cache.

Firefox does not send such headers.

But when same url is requested via img src tag, all browsers respect cache control & in their request above header is never sent

Lajpat
  • 591
  • 5
  • 19