feat: Add service worker for offline install
This commit is contained in:
@@ -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);
|
||||
})
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user