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存储。这包括存储机制,如
- localStorage (执行
localStorage.clear
), - sessionStorage (执行
sessionStorage.clear
), - IndexedDB (对每个库执行
IDBFactory.deleteDatabase
), - 服务注册线程 (对每个服务之注册线程执行
ServiceWorkerRegistration.unregister
), - AppCache,
- WebSQL 数据库,
- FileSystem API data,
- Plugin data (Flash via
NPP_ClearSiteData
).
- localStorage (执行
"executionContexts"
- 表示服务端希望浏览器重新加载本请求(
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"
规范
Specification | Status | Title |
---|---|---|
Clear Site Data | Working Draft | Initial definition. |
浏览器兼容性
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Basic support | Chrome Full support 61 | Edge ? | Firefox
Full support
63
| IE ? | Opera Full support 48 | Safari ? | WebView Android Full support 61 | Chrome Android Full support 61 | Edge Mobile ? | Firefox Android
Full support
63
| Opera Android Full support 48 | Safari iOS ? | Samsung Internet Android ? |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- User must explicitly enable this feature.
- User must explicitly enable this feature.