From 4e5b877b36d11cb1b46d670d11f071661aa4433f Mon Sep 17 00:00:00 2001 From: Jake Archibald Date: Thu, 3 Sep 2015 08:48:12 +0100 Subject: [PATCH] Use page shell --- public/js/sw/index.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/public/js/sw/index.js b/public/js/sw/index.js index b0a2abc2..796b5627 100644 --- a/public/js/sw/index.js +++ b/public/js/sw/index.js @@ -1,12 +1,10 @@ -var staticCacheName = 'wittr-static-v3'; +var staticCacheName = 'wittr-static-v4'; self.addEventListener('install', function(event) { - // TODO: cache /skeleton rather than the root page - event.waitUntil( caches.open(staticCacheName).then(function(cache) { return cache.addAll([ - '/', + '/skeleton', 'js/main.js', 'css/main.css', 'imgs/icon.png', @@ -33,8 +31,14 @@ self.addEventListener('activate', function(event) { }); self.addEventListener('fetch', function(event) { - // TODO: respond to requests for the root page with - // the page skeleton from the cache + var requestUrl = new URL(event.request.url); + + if (requestUrl.origin === location.origin) { + if (requestUrl.pathname === '/') { + event.respondWith(caches.match('/skeleton')); + return; + } + } event.respondWith( caches.match(event.request).then(function(response) {