added button

This commit is contained in:
2026-03-31 11:15:17 +05:30
parent de7ce040c8
commit fd7571c936
3 changed files with 120 additions and 40 deletions

31
public/sw.js Normal file
View File

@@ -0,0 +1,31 @@
const CACHE = 'gj-v1'
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open(CACHE).then((cache) =>
cache.addAll(['/', '/manifest.json', '/icon.svg'])
)
)
self.skipWaiting()
})
self.addEventListener('activate', (e) => {
e.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))
)
)
self.clients.claim()
})
self.addEventListener('fetch', (e) => {
// Only cache GET requests for same-origin non-API resources
if (
e.request.method !== 'GET' ||
e.request.url.includes('/api/')
) return
e.respondWith(
caches.match(e.request).then((cached) => cached || fetch(e.request))
)
})