IMB*_*IMB 8 http cache-control browser-cache http-headers clear-site-data
根据文档:
Clear-Site-Data 标头清除与请求网站关联的浏览数据(cookie、存储、缓存)
现在尝试一下,您可以在屏幕截图(Firefox v76)中看到,在Clear-Site-Data浏览器中的“响应”部分中进行了设置,但是您仍然可以看到资产“已缓存”:
注意:即使在一段时间后来回导航后,缓存的资源似乎也没有被清除。
我的印象是这会立即发生,但我无法让它发挥作用。这应该立即发生还是在一段时间后发生,或者我只是错过了其他一些事情?
为关心的人更新:
Clear-Site-Data似乎只适用于localhost或https
这应该立即发生还是在一段时间后发生,或者我只是错过了其他一些事情?
它应该立即发生。规范(草案)指出:
如果
Clear-Site-Data标头存在于从网络接收的 HTTP 响应中,则在将响应呈现给用户之前必须清除数据。
此外,正如您在此评论中提到的,仅当请求是安全的( 或 )时才支持https它localhost。
我准备了一个简单的测试,有两个资源:
index.html-- 链接到 CSS 文件的页面,还接受查询参数以在响应中?clear包含标头CSDstyle.css-- 具有随机颜色的 CSS 页面,以明确何时重新生成,并声明自身为可缓存这与 Firefox 76.0.1 中指定的行为相同;在接收带有 的资源时Clear-Site-Data: "cache",在获取其子资源之前会清除缓存。
Clear-Site-Data:index.html通过输入 URL 并点击来获取Enterstyle.css是从缓存中提供的,并且页面颜色不会改变Clear-Site-Data:index.html?clear通过输入 URL 并点击来获取Enterstyle.css不是从缓存中提供的,并且页面颜色会发生变化#!/usr/bin/python3
import http.server
import socketserver
import random
PORT = 8000
class SampleDataHandler(http.server.SimpleHTTPRequestHandler):
def do_GET(self):
if ".css" in self.path:
self.send_response(200)
self.send_header('Content-Type', 'text/css')
self.send_header('Cache-Control', 'max-age=3600')
self.end_headers()
color = b"%06x" % random.randint(0, 0xFFFFFF)
self.wfile.write(b"html{background-color: " + color + b";}\n")
else:
self.send_response(200)
if '?clear' in self.path:
self.send_header('Clear-Site-Data', '"cache"')
self.end_headers()
self.wfile.write(b"<link rel=stylesheet href=style.css>This is the content.\n")
httpd = socketserver.TCPServer(("", PORT), SampleDataHandler)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9408 次 |
| 最近记录: |