Clear-Site-Data

Baseline 2023 *
Newly available

Since September 2023, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.

* Some parts of this feature may have varying levels of support.

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

Header type Response header
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 存储。这包括存储机制,如

"executionContexts"

表示服务端希望浏览器重新加载本请求 (Location.reload).

"*" (通配符)

表示服务端希望清除原请求响应的所有类型的数据。如果在此头的未来版本中添加了更多数据类型,它们也将被涉及。

示例

登出

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

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

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

Clear-Site-Data: "cookies"

规范

Specification
Clear Site Data
# header

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Clear-Site-Data
"cache"
"clientHints"
Experimental
"cookies"
"executionContexts"
Experimental
Secure context required
"storage"
"*" (wildcard)

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.

参见