【发布时间】:2018-04-11 11:58:48
【问题描述】:
我的爱好网站上有一个服务人员,其 install 事件处理程序看起来像这样(在 TypeScript 中):
/**
* When the service worker is being intalled, download the required assets into a temporary cache
* @param e The intall event
*/
function installHander(e: ExtendableEvent): void {
"use strict";
// Put updated resources in a new cache, so that currently running pages
// get the current versions.
e.waitUntil(caches.delete("core-waiting").then(() => {
return caches.open("core-waiting").then((core) => {
const resourceUrls = [
"/",
"/loading/",
"/offline/",
"/css/site.css",
"/js/site.js"
];
return Promise.all(resourceUrls.map((key) => {
// Make sure to download fresh versions of the files!
return fetch(key, { cache: "no-cache" })
.then((response) => core.put(key, response));
}))
// Don't wait for the client to refresh the page (as this site is designed not to refresh)
.then(() => (self as ServiceWorkerGlobalScope).skipWaiting());
});
}));
}
在 Firefox 中这工作得很好,但 Chrome 65 会从 caches.open("core-waiting") 返回 undefined,所以当我尝试在 core 上调用 put 时会引发错误。 According to the docs,这应该是不可能的。知道这里发生了什么吗?
【问题讨论】:
标签: javascript google-chrome browser-cache