feat: 首次推送到Gitea - 完整项目代码 + 安全加固 + 知识库
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
// Simple service worker for PWA
|
||||
const CACHE_NAME = 'zhuiguang-v1';
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(clients.claim());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', (event) => {
|
||||
// Network-first strategy for API routes
|
||||
// Cache-first for static assets
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
if (url.pathname.startsWith('/_next/') || url.pathname.includes('/fonts/') || url.pathname.includes('/logos/')) {
|
||||
// Cache static assets
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((cached) => {
|
||||
const fetchPromise = fetch(event.request).then((response) => {
|
||||
if (response.ok) {
|
||||
const clone = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
||||
}
|
||||
return response;
|
||||
});
|
||||
return cached || fetchPromise;
|
||||
})
|
||||
);
|
||||
}
|
||||
// All other requests: network-only (don't cache dynamic content)
|
||||
});
|
||||
Reference in New Issue
Block a user