浏览器如何比较URL进行缓存? [英] How do browsers compare URLs for caching?

查看:316
本文介绍了浏览器如何比较URL进行缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体来说,URL的哪些部分用于比较。假设我在 https://www.example.com/a/b/test.css 提供CSS样式表,并为 cache提供了适当的HTTP标头-control 最大年龄等。稍后用户访问以下每个URL时,以下哪个URL将提供缓存的文件?

Specifically, what portions of the URL are used for comparison. Suppose I serve a CSS stylesheet at https://www.example.com/a/b/test.css with the appropriate HTTP headers for cache-control, max-age, etc. When a user goes to each of the following URLs later, which of them will serve the cached file?

https://www.example.com/a/b/test.css
https://www.example.com/a/b/test.css?abc=123
https://www.example.com/a/b/test.css#abc=124

基本上,我要问的是浏览器决定是否比较URL字符串的搜索和哈希部分是否使用缓存的资源。此外,这种比较逻辑是否在浏览器之间是一致的,还是在某些标准中的其他部分?

Basically, what I'm asking is whether or not the "search" and "hash" portion of the URL string are compared when the browser decides whether or not to use a cached resource. Further, is this comparison logic consistent across browsers, or otherwise part of some standard?

推荐答案

RFC 7234 状态

RFC 7234 states:


主缓存键由请求方法和目标URI组成。

The primary cache key consists of the request method and target URI.

从根本上说,RFC 7230 解释

More fundamentally, RFC 7230 explains that:


目标URI排除了引用的片段部分(如果有的话)
,因为片段标识符是为客户端处理保留的。

The target URI excludes the reference's fragment component, if any, since fragment identifiers are reserved for client-side processing

这两个资源在一起,前两个资源等效(因为查询是URI的一部分)。最后一个引用与第一个相同的资源。这是标准规范的行为。

Putting those two together, the first two resources are not equivalent (as the query is part of the URI). The last refers to the same resource as the first. This is standard-specified behaviour.

但是,请注意,规范的先前版本已声明

However, note that a previous version of the spec stated:


注意:[RFC2616]第13.9条禁止通过计算具有查询组件的URI的
启发式新鲜度(即那些包含'?'的
)来进行缓存。实际上,还没有广泛地实现

Note: Section 13.9 of [RFC2616] prohibited caches from calculating heuristic freshness for URIs with query components (i.e., those containing '?'). In practice, this has not been widely implemented.

这表明某些实现不会缓存第二个示例,除非专门告诉它可以缓存。

which suggests that some implementations wouldn't cache the second example unless specifically told that it was cacheable.

这篇关于浏览器如何比较URL进行缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆