feat: add PWA support
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

This commit is contained in:
2025-06-17 20:02:46 +08:00
parent de40dd1365
commit 6e47c0fac3
3 changed files with 53 additions and 0 deletions

23
static/service-worker.js Normal file
View 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))
);
});