Can link prefetch be used to cache a JSON API response for a later XHR request? Can link prefetch be used to cache a JSON API response for a later XHR request? google-chrome google-chrome

Can link prefetch be used to cache a JSON API response for a later XHR request?


Yes you should be able to preload JSON Read here.

fetch: Resource to be accessed by a fetch or XHR request, such as an ArrayBuffer or JSON file.

So try this syntax:

<link rel="preload" href="/api/config" as="fetch">


From MDN:

Link prefetching is a browser mechanism, which utilizes browser idle time to download or prefetch documents that the user might visit in the near future.

IMO, prefetching data for the user, before he need it for future navigation is quite similar to prefetching an image before the user navigates to it.

Another approach can be done with web worker, fetching data in a parallel thread.