缓存控制默认是公开的还是私有的?

6
如果我在Cache-Control头中不指定publicprivate指令,那么默认行为是什么?它是否可以被代理服务器缓存?
1个回答

4

我在webmasters.stackexchange.com上找到了解答。引用如下:

See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.3:

The max-age directive on a response implies that the response is
cacheable (i.e., "public") unless some other, more restrictive cache
directive is  also present. 

It's conceivable (likely?) that there are proxies in the wild which break this but since the only failure mode could be treating a public resource as private the consequences should be minimal beyond a modest performance hit. You'll have far more problems with proxies which do things like cache resources far beyond your specified max-age.


我还会添加 https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.8 上的信息:“当共享缓存 (参见第13.7节) 收到包含授权字段的请求时,除非存在特定的例外情况,否则它不得将相应的响应作为回复返回给任何其他请求。” - marzelin
1
仔细阅读 MDN 可以发现一个稍微不同的答案——“public”会覆盖请求的默认“可缓存性”。https://stackoverflow.com/a/66660215/613540 - Robin Winslow

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接