我有一个非常简单的服务工作者,可添加离线支持。 fetch处理程序如下所示
self.addEventListener("fetch", function (event) {
var url = event.request.url;
event.respondWith(fetch(event.request).then(function (response) {
//var cacheResponse: Response = response.clone();
//caches.open(CURRENT_CACHES.offline).then((cache: Cache) => {
// cache.put(url, cacheResponse).catch(() => {
// // ignore error
// });
//});
return response;
}).catch(function () {
// check the cache
return getCachedContent(event.request);
}));
我们偶尔会在在线加载特定脚本时看到net::ERR_CONNECTION_RESET错误。由于服务工作者从浏览器缓存中获取文件,该错误并非来自服务器。Chrome的网络选项卡显示服务工作者已成功从磁盘缓存中获取了文件,但浏览器对服务工作者的请求显示为(失败)。
有人知道引起此问题的根本原因吗?我的服务工作者实现存在问题吗?