5

I am fetching a resource from my RESTful web service, and in the response I add these two headers:

Cache-Control: public, max-age=120
ETag: "3D03F8066015A1438532E049AE5E16EA"

The first time the browser got this response it cached it correctly for 2 minutes.

However, the next time I requested the resource, my browser now sent an IfNoneMatch header, and got a 304 Not Modified as expected, along with another Cache-Control header to cache for 2 minutes.

BUT the browser did not cache the response. I keep refreshing the page, and it keeps making the request, and therefore keeps getting 304 Not Modified.

Is this a normal behavior?

How do I tell the browser to revalidate its cached resource for 2 more minutes, after it gets a 304 Not Modified, and to not make any more requests?

John Hascall
  • 9,176
  • 6
  • 48
  • 72
Matias Cicero
  • 25,439
  • 13
  • 82
  • 154
  • possible duplicate of [Should HTTP 304 Not Modified-responses contain cache-control headers?](http://stackoverflow.com/questions/1587667/should-http-304-not-modified-responses-contain-cache-control-headers) – Joe Nov 29 '14 at 11:46
  • Read over the question @Joe linked. What you describe sounds like the correct behavior. When you say "the browser did not cache the response" ... how do you know this? A 304 indicates that it DID cache it. Also, if you refresh over and over for longer than 2 minutes and it is still getting a 304, then the browser applied the 'new' TTL from the 304 responses. – allenru Nov 13 '15 at 03:25
  • The browser provides the `ETag` of the cached asset in the browser on the `If-None-Match` HTTP request header, then the server checks the token against current assets in the cache. If the `Etag` and `If-None-Match` headers match the `304 Not Modified` response is sent to the browser. This process ocurrs every 120 seconds based on the `max-age`. – jkutianski Mar 07 '19 at 19:34

0 Answers0