From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/http/headers/vary/index.html | 81 ++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 files/zh-cn/web/http/headers/vary/index.html (limited to 'files/zh-cn/web/http/headers/vary') diff --git a/files/zh-cn/web/http/headers/vary/index.html b/files/zh-cn/web/http/headers/vary/index.html new file mode 100644 index 0000000000..51f2c1bec6 --- /dev/null +++ b/files/zh-cn/web/http/headers/vary/index.html @@ -0,0 +1,81 @@ +--- +title: Vary +slug: Web/HTTP/Headers/Vary +translation_of: Web/HTTP/Headers/Vary +--- +
{{HTTPSidebar}}
+ +

Vary 是一个HTTP响应头部信息,它决定了对于未来的一个请求头,应该用一个缓存的回复(response)还是向源服务器请求一个新的回复。它被服务器用来表明在 content negotiation algorithm(内容协商算法)中选择一个资源代表的时候应该使用哪些头部信息(headers).

+ +

在响应状态码为 {{HTTPStatus("304")}} Not Modified  的响应中,也要设置 Vary 首部,而且要与相应的 {{HTTPStatus("200")}} OK 响应设置得一模一样。

+ + + + + + + + + + + + +
Header type{{Glossary("Response header")}}
{{Glossary("Forbidden header name")}}no
+ +

语法

+ +
Vary: *
+Vary: <header-name>, <header-name>, ...
+
+ +

说明

+ +
+
*
+
所有的请求都被视为唯一并且非缓存的,使用{{HTTPHeader("Cache-Control")}}: no-store,来实现则更适用,这样用于说明不存储该对象更加清晰。
+
<header-name>
+
 逗号分隔的一系列http头部名称,用于确定缓存是否可用。
+
+ +

例子

+ +

动态服务

+ +

哪种情况下使用 Vary: 对于User-Agent 头部信息,例如你提供给移动端的内容是不同的,可用防止你客户端误使用了用于桌面端的缓存。 并可帮助Google和其他搜索引擎来发现你的移动端版本的页面,同时告知他们不需要Cloaking

+ +
Vary: User-Agent
+ +

定义

+ + + + + + + + + + + + +
版本标题
{{RFC("7231", "Vary", "7.1.4")}}Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
+ +

浏览器兼容性

+ + + +

{{Compat("http.headers.Vary")}}

+ +

更多关于浏览器兼容性:

+ + + +

更多

+ + -- cgit v1.2.3-54-g00ecf