Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 迭代器getter不可调用_Javascript_Service Worker - Fatal编程技术网

Javascript 迭代器getter不可调用

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

我正试图下载一个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(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数组,您希望获取并添加到缓存中。”