Search code examples
validationhttp-headersetaghttp-caching

ETags: Validation and Cache max-age


I have been using ETags for a good while now and I am pleased with how they can be used and what they allow to be done.

However, I am sometimes experiencing ETag validation requests. On my server, I can see that my browser hits the resource URL, and then gets the "Not changed" response. But, it still is a request. 

How can a clever webserver (I am coding mine in NodeJS) avoid being hit with validation for as long as cache-control: max-age=N goes?

For instance, my max-age indicates a TTL of 30 days. The client shouldn't validate the Etag in that time, at all. Is that possible?


Solution

  • Not possible to force this at server level as it's the client that decides this.

    Cache control headers like ETags are hints not directives. The browser is free to ignore these hints (for example when you refresh a page you explicitly ask the browser to recheck the resources). Some browsers also periodically recheck resources.

    Saying that, if your cache control headers are set up correctly then these requests should be infrequent and the norm should be for the requests not to be sent.