删除服务工作者缓存崩溃

时间:2019-04-09 10:28:53

标签: javascript service-worker angular-service-worker

我已将以下(示例)代码添加到我的应用程序(Angular应用程序,对于任何JS应用程序均适用)以删除serviceworker缓存:

if ('serviceWorker' in navigator) {
    if ('caches' in window) {
        caches.keys().then((keyList) => {
            return Promise.all(keyList.map(function (key) {
                return caches.delete(key);
            }));
        });
    }
}

但是对于在Windows上使用Chrome 72及更高版本的某些用户,我经常收到带有以下错误的崩溃报告:

TypeError · undefined is not a function

功能

caches.keys

任何人都不知道为什么会发生这种情况。

1 个答案:

答案 0 :(得分:0)

keys method is only found on Cache objects

您可以从cache.open函数中获取缓存对象。

用法示例:

caches.open(name).then(function(cache) {
  cache.keys().then(function(keys) {
    //Do something with keys
  });
})
相关问题