-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Service Worker for offline support
- Loading branch information
adambar
committed
Nov 15, 2016
1 parent
aa55e13
commit 578c4a2
Showing
4 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
this.addEventListener('install', function (event) { | ||
event.waitUntil( | ||
caches.open(VERSION).then(function (cache) { | ||
let files = [ | ||
'/', | ||
'/index.html', | ||
'/scripts/main.js', | ||
'/scripts/vendor.js', | ||
'/styles/main.css', | ||
'/styles/vendor.css', | ||
'/images/logo.svg', | ||
'/fonts/Material-Design-Icons.woff' | ||
]; | ||
|
||
groups.forEach(function (group) { | ||
group.features.forEach(function (feature) { | ||
files.push(`/${feature.id}.html`); | ||
}); | ||
}); | ||
|
||
return cache.addAll(files); | ||
}) | ||
); | ||
}); | ||
|
||
this.addEventListener('activate', function (event) { | ||
event.waitUntil( | ||
caches.keys().then(function (keyList) { | ||
return Promise.all(keyList.map(function (key) { | ||
if (key !== VERSION) { | ||
return caches.delete(key); | ||
} | ||
})); | ||
}) | ||
); | ||
}); | ||
|
||
this.addEventListener('fetch', function (event) { | ||
event.respondWith( | ||
caches.open(VERSION) | ||
.then(function (cache) { | ||
return cache.match(event.request, {ignoreSearch: true}) | ||
.then(function (response) { | ||
if (response) { | ||
return response; | ||
} | ||
|
||
return fetch(event.request) | ||
.then(function (fetchResponse) { | ||
if (event.request.url.indexOf('https://raw.githubusercontent.com') === 0) { | ||
cache.put(event.request, fetchResponse.clone()); | ||
} | ||
return fetchResponse; | ||
}); | ||
}); | ||
}) | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters