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

爷,独闯天下 提交于 2019-12-04 23:36:07

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 needs it in its future navigation is quite similar to prefetch an image before he navigates to it.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!