This repository has been archived by the owner on Mar 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #108 from nitrotap/harabushi-feature/pwa
Harabushi feature/pwa
- Loading branch information
Showing
3 changed files
with
80 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable no-restricted-globals */ | ||
const APP_PREFIX = 'mhc-'; | ||
const VERSION = 'version_01'; | ||
const CACHE_NAME = APP_PREFIX + VERSION; | ||
const urlsToCache = [ | ||
'/', | ||
'/index.html', | ||
'/dashboard', | ||
'/quizselect', | ||
'/legal', | ||
]; | ||
|
||
// Install a service worker | ||
self.addEventListener('install', event => { | ||
// Perform install steps | ||
event.waitUntil( | ||
caches.open(CACHE_NAME) | ||
.then(function(cache) { | ||
console.log('Opened cache'); | ||
return cache.addAll(urlsToCache); | ||
}) | ||
); | ||
}); | ||
|
||
// Cache and return requests | ||
self.addEventListener('fetch', event => { | ||
event.respondWith( | ||
caches.match(event.request) | ||
.then(function(response) { | ||
// Cache hit - return response | ||
if (response) { | ||
return response; | ||
} | ||
return fetch(event.request); | ||
} | ||
) | ||
); | ||
}); | ||
|
||
// Update a service worker | ||
self.addEventListener('activate', event => { | ||
event.waitUntil( | ||
caches.keys().then(function(keyList) { | ||
let cacheKeeplist = keyList.filter(function(key) { | ||
return key.indexOf(APP_PREFIX); | ||
}); | ||
cacheKeeplist.push(CACHE_NAME); | ||
|
||
return Promise.all( | ||
keyList.map(function(key, i) { | ||
if (cacheKeeplist.indexOf(key) === -1) { | ||
console.log('deleting cache : ' + keyList[i]); | ||
return caches.delete(keyList[i]); | ||
} | ||
}) | ||
); | ||
}) | ||
); | ||
}); |
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