Skip to content

Commit

Permalink
Use page shell
Browse files Browse the repository at this point in the history
  • Loading branch information
jakearchibald committed Nov 16, 2017
1 parent 7d67ebd commit 4e5b877
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions public/js/sw/index.js
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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) {
Expand Down

0 comments on commit 4e5b877

Please sign in to comment.