Skip to content

Commit

Permalink
Don't bother with seperate caching function, not gonna re-use it
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed Sep 22, 2016
1 parent 574e666 commit a6e5111
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions public/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,20 @@ self.addEventListener('fetch', function(event) {
return;
}

// Always check cache for assets
// Try cache first for assets
if(requestUrl.pathname.startsWith('/assets/')) {
checkCacheFirst(event);
event.respondWith(
caches.match(event.request)
.then(function(response) {
if (response) {
return response;
}

// If we don't have it make the request
return fetch(event.request);
}
)
);
return;
}

Expand Down Expand Up @@ -70,17 +81,3 @@ self.addEventListener('fetch', function(event) {
);
}
});

// Try cache first, if we don't have it make the request
function checkCacheFirst(event) {
return event.respondWith(
caches.match(event.request)
.then(function(response) {
if (response) {
return response;
}
return fetch(event.request);
}
)
);
}

0 comments on commit a6e5111

Please sign in to comment.