feat: Add service worker for offline install

This commit is contained in:
2026-05-31 00:43:24 +05:30
parent f37291196b
commit 12044c6ea6
4 changed files with 46 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
const CACHE_NAME = 'pascar';
const ASSETS = [
'index.html',
'manifest.json'
];
// Install: Cache the files
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS))
);
});
// Fetch: Serve from cache if offline
self.addEventListener('fetch', (e) => {
e.respondWith(
caches.match(e.request).then((response) => {
return response || fetch(e.request);
})
);
});