Why does Firefox ignore cache headers and revalidate on refresh?

后端 未结 2 1592
遥遥无期
遥遥无期 2021-01-25 17:18

I have some image resources that are immutable and can be cached forever. Chrome seems to respect my response headers, and does not re-validate the resources:

H

2条回答
  •  庸人自扰
    2021-01-25 17:33

    Just to be more verbose let me elaborate on ETags. Technically, Firefox is handling it correctly. When an Etag is present, the client or intermediary caches need to perform a GET or HEAD ensuring the content being served hasn't changed.

    The If-None-Match header tells the server what version or versions it has. If it has not changed, the server/proxy returns a 304.

    You can modify the revalidation behavior by making it a weak ETag. That is done by including W/ in front of the ETags value, i.e. ETag: /W #########. This can be handled on your server or if you can't control it by rewrite rules on your CDN.

    The possible workaround for Firefox is adding the Cache-Control Immutable options. Cache-Control: Immutable. Without looking at the code in Firefox caching heuristics I can't say for sure but it should be easy to test.

    Other servers will ignore the header if they don't support it.

    Etags also don't work with byte-range requests. So if you don't have a specific reason for using them consider turning them off.

提交回复
热议问题