Draex_
Draex_

Reputation: 3474

Is it possible to refresh a preloaded JSON in mobile Safari?

I use HTTP header Link to speed up loading of user data on my page:

Link: </api/GetUserData>; rel="preload"; as="fetch"

When user data changes, I need to load the data again via fetch. This works okay in Chrome, but iOS Safari (17.6.1) caches the response and always uses the preloaded version, even on new full page refresh. I’ve tried disabling caching via HTTP headers:

Cache-Control=no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0
Pragma=no-cache

But this doesn't stop mobile Safari from caching that resource. The only solution I see right now is to change the URL of the preloaded resource on every page load. Is there anything else that can be done to retrieve fresh user data?

Is there any way to refresh the preloaded resource in mobile Safari?

Upvotes: 1

Views: 51

Answers (1)

Draex_
Draex_

Reputation: 3474

If you issue a fetch request that can't be used with preloaded data (header list is not empty):

fetch('/api/GetUserData', {
    headers: {
        "Accept": "application/json"
    }
});

It causes mobile Safari to flush the cache. On subsequent page load, preload request is fetched again.

Upvotes: 0

Related Questions