Does max-age update automatically if a conditional header returns 304?

361 Views Asked by At

Imagine a resource with a max-age of 60 seconds:

  • After 1 minute, the browser sends a conditional header If-None-Match
  • This checks if the etag of the resource has changed.
  • If the etag has not changed, the server will return a 304 Not Modified response.

Will this response automatically add a new 60 seconds to the max-age? Or is this a case server needs to explicitly handle.

1

There are 1 best solutions below

0
On BEST ANSWER

In section 4.2 of the HTTP caching specification it says the following:

A response's age is the time that has passed since it was generated by, or successfully validated with, the origin server.

The max-age directive tells the HTTP cache of the client that the response is good for 60 seconds. So once the server sends a 304 response, that cached response will be good for another 60 seconds.

There's nothing to handle for the server here. It's up to the client's caching implementation to freshen the responses upon receiving a 304 response.