http-headersbrowser-cacheetaghttp-cachingmax-age

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


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

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


Solution

  • 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.