Files
blog/static/service-worker.js
changsongd 6e47c0fac3
All checks were successful
Gitea Actions Demo / build-and-deploy-to-local-server (push) Successful in 2m58s
Gitea Actions Demo / deploy-to-remote-server (push) Successful in 2s
feat: add PWA support
2025-06-17 20:02:46 +08:00

24 lines
458 B
JavaScript

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))
);
});