Javascript 迭代器getter不可调用
我正试图下载一个json文件并将其缓存,但出现了一个错误。 代码如下:Javascript 迭代器getter不可调用,javascript,service-worker,Javascript,Service Worker,我正试图下载一个json文件并将其缓存,但出现了一个错误。 代码如下: event.waitUntil( caches.open(CACHE_NAME) .then(function(cache) { // With the cache opened, load a JSON file containing an array of files to be cached return fetch('resource').then(functi
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
// With the cache opened, load a JSON file containing an array of files to be cached
return fetch('resource').then(function(response) {
// Once the contents are loaded, convert the raw text to a JavaScript object
return response.json();
}).then(function(files) {
// Use cache.addAll just as you would a hardcoded array of items
console.log('[install] Adding files from JSON file: ', files);
return cache.addAll(files);
});
})
.then(function() {
// Message to simply show the lifecycle flow
console.log(
'[install] All required resources have been cached;',
'the Service Worker was successfully installed!'
);
// Force activation
return self.skipWaiting();
})
);
mysw.js:42未捕获(承诺中)类型错误:未能在“缓存”上执行“addAll”:迭代器getter不可调用
cache.addAll(文件);似乎在制造问题 然后:
cache.addAll(files);
使用:
因为当文件的1个不可访问时(HTTP 400401等,有时也有5XX和3XX),cache.addAll(files)将失败,以避免在1个失败时全部失败,请在映射循环中使用单个catch语句
查看此答案了解更多详细信息:然后:
cache.addAll(files);
使用:
因为当文件的1个不可访问时(HTTP 400401等,有时也有5XX和3XX),cache.addAll(files)将失败,以避免在1个失败时全部失败,请在映射循环中使用单个catch语句
查看此答案以了解更多详细信息:您作为
文件传递的是什么类型的文件。。根据需要(我引述),它是“一个字符串URL数组,您希望获取并添加到缓存中。”您将传递什么类型的文件。。根据需要(我引述)“一个字符串URL数组,您希望获取并添加到缓存中。”