Search code examples
playframeworkcache-controletagif-none-match

Does If-None-Match header overrules Cache-Control: max-age?


I have a webapp that serves an image:

enter image description here

I'm clearly setting the Cache-Control header properly, and the web server is setting the Etag.

The problem is that the resources is being If-None-Matched every single time effectively ignoring the Cache-Control header. (The framework is returning 304 accordingly but the roundtrip exists).

I've read that the Etag header may overrule Cache-Control and still go to check the match even if the resource is local and valid. This makes no sense to me.

Anyone knows what's going on? What am I missing here?

PD: The web server is a Play! application


Solution

  • Finally got it. Some browsers (Google Chrome and Firefox for sure) ignore the local cache when you reload the page with CMD+R or F5.

    In my case, no matter how high I set the max-age, a page reload will always force the If-None-Match check and get a 304 back. Navigating through the website by clicking links will not trigger this behaviour and caches will work just fine.

    Note: I didn't noticed this since in a single page webapp (like mine) there's no "link clicking navigation", since most of them are loaded at the beginning.