13

I'm trying to implement a cache clearing button for our website that will append the Clear-Site-Data header on a specific route so we can be relatively sure that the users are getting the latest javascript, css, etc. after a release. I'm assigning the header in my ActionMethod like so: enter image description here

According to developer tools, I'm getting the header on the client:

enter image description here

So, Chrome is trying to do what I'm asking but it's throwing an error saying the types I'm passing it are unrecognized: console error when loading page with Clear-Site-Data header

Am I missing something with how I'm creating the header? Is this a bug?

Mike Devenney
  • 1,758
  • 1
  • 23
  • 42

1 Answers1

16

Ok, so here we are a few months down the road and I finally remembered to come back and post the working solution. What I didn't understand at the time I asked the question was that the quotes are expected to be treated as literal in the response header examples I found. So the code I posted in my question was missing a few \ characters in the strings. What ended up working was this:

enter image description here

The headers on the client now look like this (note the quotes around cache and storage):

enter image description here

And the cache and localStorage are cleared as desired. Hope this helps someone else as well!

Mike Devenney
  • 1,758
  • 1
  • 23
  • 42
  • 1
    I just kept experimenting and looking for examples of actual sites that used it. A friend used it on one of his sites and when I inspected the response from his in Chrome Tools I saw that cache had double quotes around it in the inspector for his but not mine. That's when I realized that the quotes were part of the header and not just signifying that cache was supposed to be a string. – Mike Devenney Mar 13 '19 at 13:24
  • It's interesting that there doesn't seem to be a standard for how the entries are formatted (that I could find). In the screenshot above, Cache-Control has no quotes around its values, Clear-Site-Data does. I wonder if someone could comment on why that is? I was unable to find a guide for properly formatting values but to be honest, I stopped looking when I found the solution to the problem at hand. – Mike Devenney Mar 19 '19 at 11:51
  • 1
    Thanks a lot, I had the same issue with my python fastapi app and it works with Firefox however it doesn't work with chrome which is very weird !! I'll investigate more on this – a3k Feb 27 '21 at 00:57
  • Will it work for safari browser? – Vimalraj Feb 09 '22 at 04:17
  • We don't develop against Safari (controlled corporate environment where Chromium based browsers are required). I haven't tested it against Safari. It works in Chrome, Edge and Firefox though. Give it a shot! – Mike Devenney Feb 09 '22 at 15:14
  • To the downvoter... This answer documents a less than intuitive way to specify headers. posted this hoping to help anyone else who ran into the same problem. 17 others found it useful enough to upvote... care to explain why you voted it down? – Mike Devenney Aug 29 '23 at 18:13