ETag with no Cache-Control header in http response

假如想象 提交于 2021-02-04 18:31:06

问题


I am trying to learn some basics about HTTP. I've inspected a some HTTP response headers and noticed 2 things that confused me:

  • There was no cache-control header and

  • ETag header was present.

The way I understood ETag is that, client sends ETag in a requests to a cache, and cache revalidates resources Etag with the server. But if there is no Cache-Control header in response, than all subsequent requests do the revalidation directly with the server and completely omit cache. Is this the case or am I missing something? Does something else happen when there is no cache-control header present in response? Why is ETag even present if all request will go to the server directly anyway?


回答1:


The absence of a cache-control header does not mean a resource cannot be cached - it's up to the client (i.e. the web browser) to decide how to handle this undefined state.

Caching it (whether in memory or in disk) and only using that cached version if ETag validates seems a perfectly reasonable implementation to me.

If you don't want a resource cached then you should explicitly say this with a cache-control header of "max-age=0, no-store, no-cache, must-revalidate".



来源:https://stackoverflow.com/questions/37600898/etag-with-no-cache-control-header-in-http-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!