From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../web/http/headers/clear-site-data/index.html | 108 +++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 files/zh-cn/web/http/headers/clear-site-data/index.html (limited to 'files/zh-cn/web/http/headers/clear-site-data') diff --git a/files/zh-cn/web/http/headers/clear-site-data/index.html b/files/zh-cn/web/http/headers/clear-site-data/index.html new file mode 100644 index 0000000000..01aae20940 --- /dev/null +++ b/files/zh-cn/web/http/headers/clear-site-data/index.html @@ -0,0 +1,108 @@ +--- +title: Clear-Site-Data +slug: Web/HTTP/Headers/Clear-Site-Data +tags: + - HTTP + - http头 + - 头 +translation_of: Web/HTTP/Headers/Clear-Site-Data +--- +

{{HTTPSidebar}}

+ +

Clear-Site-Data 响应头,表示清除当前请求网站有关的浏览器数据(cookie,存储,缓存)。它让Web开发人员对浏览器本地存储的数据有更多控制能力。

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

语法

+ +

Clear-Site-Data  可以接受一个或多个参数,如果想要清除所有类型的数据,可以使用通配符("*"

+ +
// 单个参数
+Clear-Site-Data: "cache"
+
+// 多个参数 (用逗号分隔)
+Clear-Site-Data: "cache", "cookies"
+
+// 通配
+Clear-Site-Data: "*"
+
+ +

指令

+ +
+
"cache"
+
表示服务端希望删除本URL原始响应的本地缓存数据(即 :浏览器缓存,请参阅HTTP缓存)。根据浏览器的不同,可能还会清除预渲染页面,脚本缓存,WebGL着色器缓存或地址栏建议等内容。
+
"cookies"
+
表示服务端希望删除URL响应的所有cookie。 HTTP身份验证凭据也会被清除。会影响整个主域,包括子域。所以https://example.com以及https://stage.example.com的Cookie都会被清除。
+
"storage"
+
表示服务端希望删除URL原响应的所有DOM存储。这包括存储机制,如 +
    +
  • localStorage (执行 localStorage.clear),
  • +
  • sessionStorage (执行 sessionStorage.clear),
  • +
  • IndexedDB (对每个库执行  {{domxref("IDBFactory.deleteDatabase")}}),
  • +
  • 服务注册线程 (对每个服务之注册线程执行 {{domxref("ServiceWorkerRegistration.unregister")}}),
  • +
  • AppCache,
  • +
  • WebSQL 数据库,
  • +
  • FileSystem API data,
  • +
  • Plugin data (Flash via NPP_ClearSiteData).
  • +
+
+
"executionContexts"
+
表示服务端希望浏览器重新加载本请求({{domxref("Location.reload")}}).
+
"*" (通配符)
+
表示服务端希望清除原请求响应的所有类型的数据。如果在此头的未来版本中添加了更多数据类型,它们也将被涉及。
+
+ +

示例

+ +

登出

+ +

如果用户退出您的网站或服务,您可能希望删除本地存储的数据。您可以通过在https://example.com/logout的响应头增加Clear-Site-Data,以达到目的:

+ +
Clear-Site-Data: "cache", "cookies", "storage", "executionContexts"
+ +

清除cookie

+ +

如果它在https://example.com/clear-cookies的响应头中出现,则同一域 https://example.com和所有子域(如https://stage.example.com等)中的所有Cookie,将都被清除。

+ +
Clear-Site-Data: "cookies"
+ +

规范

+ + + + + + + + + + + + + + +
SpecificationStatusTitle
Clear Site DataWorking DraftInitial definition.
+ +

浏览器兼容性

+ + + +

{{Compat("http.headers.Clear-Site-Data")}}

+ +

参见

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