Browse Source

Enable selective caching

pm2
Luke Childs 9 years ago
parent
commit
3d81765260
  1. 12
      public/sw.js

12
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

Loading…
Cancel
Save