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?

3
  • possible duplicate of Should HTTP 304 Not Modified-responses contain cache-control headers? Commented Nov 29, 2014 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. Commented Nov 13, 2015 at 3: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. Commented Mar 7, 2019 at 19:34

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.