feat: add PWA support
This commit is contained in:
23
static/service-worker.js
Normal file
23
static/service-worker.js
Normal file
@ -0,0 +1,23 @@
|
||||
const cacheName = 'v1';
|
||||
|
||||
const cacheAssets = [
|
||||
'/',
|
||||
'/index.html',
|
||||
'/style.css',
|
||||
// 可以添加其他需要缓存的资源路径
|
||||
];
|
||||
|
||||
self.addEventListener('install', e => {
|
||||
e.waitUntil(
|
||||
caches.open(cacheName).then(cache => {
|
||||
console.log('Caching files...');
|
||||
return cache.addAll(cacheAssets);
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', e => {
|
||||
e.respondWith(
|
||||
fetch(e.request).catch(() => caches.match(e.request))
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user