Safari Caching GET request even with disabled cache

Samuel Hapak

I have set all headers that I know of to disable caching (even disabling ETAG) on my server, yet Safari still occasionally (about 50% times) caches my requests.

Workflow

I am implementing oauth 1, so:

  1. Browser makes GET /api/user request

  2. Server returns 405

  3. Browser redirects to 3rd party website to authenticate

  4. Browser is redirected to api/callback which stores some info into cookie.

  5. Browser is redirected back to original route.

  6. Browser makes GET /api/user request which should be successful, however it gets 405 served from disk cache instead.

Request summary from Safari Network Inspector

Summary

URL: http://localhost:3000/api/user

Status: 405 Method Not Allowed

Source: Disk Cache

Request

No request, served from the disk cache.

Response

Transfer-Encoding: Identity

Content-Type: application/json; charset=utf-8

Pragma: no-cache

Cache-Control: private, no-cache, no-store, must-revalidate, max-age=0

Vary: Cookie, Accept-Encoding

Date: Wed, 23 Jan 2019 11:34:23 GMT

Content-Encoding: gzip

Expires: Thu, 01 Dec 1994 16:00:00 GMT

Connection: close

x-powered-by: Express

Conclusion

I have no idea what's wrong and I will greatly appreciate any help. My Safari version is 12.0.2. I wasn't able to replicate this issue with Chrome.

Samuel Hapak

Use Vary: *. This magically solved my problem.

This answer helped me: https://stackoverflow.com/a/2068353/1364158

Alternatively, you can really force browser to load a new version of request by including some meaningless random query arg in your url, e.g. /api/user?ts=18284

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Hystrix Request Caching by Example

GET Oauth Token API not working in Elastic Search Even Security is Disabled

Force `go get` and `go install` to use cache even if it's ancient

Why is iBATIS giving stale results, even with caching disabled?

Angular GET request error, but only on safari iOS

Unwanted caching a GET request with AFNetworking

Flask Cache not caching

HTTP Request headers and caching

Caching results of a Django function call with cache.get_or_set()

how to get a full page web app even in safari?

Cloudflare not caching files even when headers are "Cache-Control: public, max-age=86400"

Rails 5 with memcached caching issue, wrong fragment cache is sticking even if I clear the cache

Browser caching request/response without any Cache-Control header

Why isn't Chrome caching responses, even when cache-control header is present?

Caching Videos in Safari using Workbox

Criteria query cache caching in Eclipselink?

Firefox caching a site even after clearing the site's cache?

jQuery Ajax GET request won't cache

Get IDFA iOS 8 is always accessible even IDFA disabled in settings

prevent caching of xmlhttp request

sssd caching user credentials even the cache_credentials is set to false

GET request served from cache in firefox but not in chrome?

Get request is not authorized when CSRF is disabled in Spring Security

Amazon S3 caching does not work even if I have set metadata cache control to several days

Nginx/Django caching site even when caching explicitly disabled

Should Cache-Control request headers influence server-side caching?

Do responses get cached even if there is no cache-control header?

Caching in rails for the duration of a request

Mule 4 Object store and caching - store records from Db in cache and then Validate incoming request against them from cache - seems it is possible