httphttp-headersbrowser-cachecache-controlclear-site-data

Expected behavior when Clear-Site-Data header is set?


According to the docs:

Clear-Site-Data header clears browsing data (cookies, storage, cache) associated with the requesting website

Now trying it, you can see in the screenshot (Firefox v76) that in the Response section, Clear-Site-Data was set in the browser, but, you can still see the assets as "cached":

Note: Even after navigating back/forth after some time, the cached assets doesn't seem to get cleared.

enter image description here

I'm under the impression this will happen instantly but I can't get it to work. Is this suppose to happen instantly or after some time, or I am just missing some else?


Update for those who care:

Clear-Site-Data appears to only work on localhost or https


Solution

  • Is this suppose to happen instantly or after some time, or I am just missing some else?

    It is supposed to happen instantly. The (draft) spec states:

    If the Clear-Site-Data header is present in an HTTP response received from the network, then data MUST be cleared before rendering the response to the user.

    Additionally, as you mention in this comment it is only supported when a request is secure (either https or localhost).

    I prepared a simple test, with two resources:

    This behaved as specified with Firefox 76.0.1; on receiving a resource with Clear-Site-Data: "cache", the cache is cleared before fetching its subresources.

    Without Clear-Site-Data:

    With Clear-Site-Data:

    Code:

    #!/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()