Commit 248a62e0 authored by Julien Enselme's avatar Julien Enselme

Make the SW cache basic pages

At this point, we have a PWA that can responds to request even when offline.
parent ac2b9007
const VERSION = '1.0.0';
const staticCachePrefix = 'static';
const staticCacheName = `${staticCachePrefix}-${VERSION}`;
self.addEventListener('install', (event) => {
console.log('[SW] Installing SW version:', VERSION);
event.waitUntil(
caches.open(staticCacheName)
.then(cache => {
console.log('[SW] Caching app shell');
cache.addAll([
'/',
'/offline/',
]);
}),
);
});
self.addEventListener('fetch', (event) => {
// Let the browser do its default thing
// for non-GET requests.
if (event.request.method !== 'GET') {
return;
}
event.respondWith(
caches.match(event.request)
.then((response) => {
// If we have the response in the cache, we return it.
// If not, we try to fetch it.
return response || fetch(event.request);
}),
);
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment