如何解决激活服务工作者后重新发送请求
我在asp核心中使用Service Worker,因此感到困惑,因为当Service Worker激活并且我在浏览器请求中按F12键时,在离线模式或在线模式下都没有问题!!!!!!
我更换了服务人员,但是又发生了。
这是我的服务人员:
(function () {
'use strict';
var version = 'v1.0::NetworkFirst';
var offlineUrl = "/Home/Offline";
function updateStaticCache() {
return caches.open(version)
.then(function (cache) {
return cache.addAll([
offlineUrl,'/','/Home/Index','/Home/Contact','/Home/About'
]);
});
}
function addToCache(request,response) {
if (!response.ok)
return;
var copy = response.clone();
caches.open(version)
.then(function (cache) {
cache.put(request,copy);
});
}
self.addEventListener('install',function (event) {
event.waitUntil(updateStaticCache());
});
self.addEventListener('activate',function (event) {
event.waitUntil(
caches.keys()
.then(function (keys) {
return Promise.all(keys
.filter(function (key) {
return key.indexOf(version) !== 0;
})
.map(function (key) {
return caches.delete(key);
})
);
})
);
});
self.addEventListener('fetch',function (event) {
var request = event.request;
if (request.method !== 'GET') {
event.respondWith(
fetch(request)
.catch(function () {
return caches.match(offlineUrl);
})
);
return;
}
event.respondWith(
fetch(request)
.then(function (response) {
addToCache(request,response);
return response;
})
.catch(function () {
return caches.match(request)
.then(function (response) {
return response || caches.match(offlineUrl);
})
.catch(function () {
});
})
);
});
})();
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。