From 3d81765260e7d407ded674082f11c9fead134e57 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 22 Sep 2016 13:42:56 +0100 Subject: [PATCH] Enable selective caching --- public/sw.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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