如何预取外部JSON并使用它?

问题描述 投票:0回答:1
html json prefetch
1个回答
0
投票

你可以用这个

<link rel="prefetch" href="/data.json" as="fetch">

这样,浏览器将从缓存中加载资源,而不是在您要使用该文件时再次前往服务器请求该文件。

fetch('/data.json')
    .then(response => {
    // some code
    })
    .then(json => {
        // some code
    })
    .catch(console.error);
© www.soinside.com 2019 - 2024. All rights reserved.