navigator.serviceWorker.register('./service-worker.js')
if (navigator.serviceWorker) {
navigator.serviceWorker.register('./service-worker.js')
}
self.addEventListener('fetch', function(event) {
event.respondWith(fetch(event.request));
});
self.addEventListener('install', event => {
event.waitUntil(
caches.open('myCache')
.then(cache => cache.addAll([
'./index.html'
]))
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
fetch(event.request).catch(function() {
return caches.match(event.request);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
https://jakearchibald.com/2014/offline-cookbook/