0

I've just noticed that Safari on iOS keeps stale $http.get results in cache, that target my server (REST call).

However, Safari claims a status 200 (not 304), even if result is stale... troubling

I confirm that the issue comes from Safari since it's easy to check the real result through a rest call to the server.

What I do to force Safari to refresh its cache is adding a random parameter:

$http.get('myUrl?rnd=' + new Date().getTime())

Is there a better practice? Probably changing the response headers on the server directly?


My server returns this response header:

HTTP/1.1 200 OK
Server: Cowboy
Date: Tue, 11 Nov 2014 23:52:59 GMT
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Content-Encoding: gzip
Vary: Accept-Encoding
Content-Length: 495
Via: 1.1 vegur
Mik378
  • 20,929
  • 13
  • 73
  • 163

1 Answers1

1

Your response doesn't have any cache control headers. According to this answer browsers are free to do whatever they want if there are no cache control headers. In your case Safari on iOS has decided to cache the content even though that isn't what you want.

You could keep using your workaround, or you could add cache control headers in the response to tell Safari not to cache your response.

Note that RFC's might say that responses should not be cached if there are no cache control headers. (I haven't checked). But browsers often have non-standard behavior that you have to work around.

As an aside - early on in my computer networking job I thought that it was OK to not support browsers and webservers that didn't follow the RFCs. I was wrong.

Community
  • 1
  • 1
Craig S. Anderson
  • 6,150
  • 4
  • 27
  • 42
  • 1
    Got it :) So, it seems I could use the `No-Cache` header like explaining here: http://stackoverflow.com/a/2068407/985949 – Mik378 Nov 12 '14 at 02:47