2

I'm working on a web app that gets data from an API. The API includes cache headers on most resources and generally this works as expected. However, when the app modifies a resource via POST, PUT, DELETE the cache of the GET for the same URI must be invalidated. This is described in RFC 7234 4.4

In our testing it seems that IE 11 does not respect that and is returning cached resources with a 304 Not Modified response. To get around this, on the next GET request following a state change request, I have tried adding the request header Cache-Control: No-Cache, No-Store

I'm still getting a 304 Not Modified cached response.

How can I get IE 11 to ignore it's cache and go to the server again? This all works as expected in Chrome.

It's it's relevant I'm using fetch

Liam
  • 22,818
  • 25
  • 93
  • 157
A Jackson
  • 2,369
  • 7
  • 32
  • 43
  • Possible duplicate of [How to control web page caching, across all browsers?](http://stackoverflow.com/questions/49547/how-to-control-web-page-caching-across-all-browsers) – Alex Slipknot Apr 27 '17 at 11:12
  • Adding that header won't make a difference if the response is still cached in IE, it won't know about the new header. Clear the cache in IE and then retry your test. – user247702 Apr 27 '17 at 11:17
  • I added it to the Request header. The Response headers don't change. – A Jackson Apr 27 '17 at 11:29

1 Answers1

3

As I mentioned in the comment, you have to try these headers:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Alex Slipknot
  • 1,974
  • 1
  • 15
  • 24
  • must-revalidate is listed as a response directive. I'm talking about the request headers. Normally, I want the response the cached, there's just some circumstances, where on the client I know it to be old and want a fresh copy from the server – A Jackson Apr 27 '17 at 11:34
  • @AJackson understood. You can't do so. You can't control/handle client's browser request. All that you can - send response headers to tell the browser that we got to refresh the data – Alex Slipknot Apr 27 '17 at 11:40
  • Otherwise if you can modify client's request (by modifying frontend requests) and you can send some custom headers then you can implement some detection system at the backend witch will respond to you with modified response-headers – Alex Slipknot Apr 27 '17 at 11:43
  • I can control the browser's request when I'm coding in the client. See my question, I'm using javascript and fetch. I can add any request headers I want. I'm trying to find out what request headers I can use to tell the browser to ignore it's own cache. – A Jackson Apr 27 '17 at 11:44
  • Sure, see my previous comment. Easiest way to tell browser that we have to receive fresh data is to append some random parameter in request – Alex Slipknot Apr 27 '17 at 11:47
  • 1
    Based on your answer, I tried request `Cache-Control: no-cache, no-store Pragma: no-cache` and that seems to have worked so I'll accept it – A Jackson Apr 27 '17 at 11:47