diff --git a/public/sw.js b/public/sw.js index ef6128c..131fae5 100644 --- a/public/sw.js +++ b/public/sw.js @@ -39,7 +39,17 @@ self.addEventListener('fetch', function(event) { event.respondWith( fetch(event.request) - // and it fails + // Cache the latest response for certain pages + .then(function(response) { + if(requestUrl.pathname === '/') { + caches.open(cacheName).then(function(cache) { + cache.put(event.request, response.clone()); + }); + } + return response; + }) + + // If it fails .catch(function() { // Show pretty offline page