add pwa restart

This commit is contained in:
lyc
2021-09-04 20:23:01 +08:00
committed by 神戸小鳥
parent b73e547732
commit ac78231a78
12 changed files with 96 additions and 0 deletions

28
view/sw.js Normal file
View File

@@ -0,0 +1,28 @@
//缓存空间名称
var CACHE_VERSION = 'sw_v1';
var CACHE_FILES = [
'/',
];
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_VERSION)
.then(cache => cache.addAll(CACHE_FILES)
.then(() => self.skipWaiting())
));
});
self.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function (keys) {
return Promise.all(keys.map(function (key, i) {
if (key !== CACHE_VERSION) {
return caches.delete(keys[i]);
}
}));
})
);
});
self.addEventListener('fetch', function(event) {});