added reward checking
This commit is contained in:
parent
71665f6984
commit
f03997c4a4
6 changed files with 90 additions and 18 deletions
35
scripts/offline.js
Normal file
35
scripts/offline.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
/* offline.js
|
||||
Make app available offline */
|
||||
|
||||
const CACHE_NAME = `RollDice`;
|
||||
|
||||
// Use the install event to pre-cache all initial resources.
|
||||
self.addEventListener('install', event => {
|
||||
event.waitUntil((async () => {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
cache.addAll(['/']);
|
||||
})());
|
||||
});
|
||||
|
||||
self.addEventListener('fetch', event => {
|
||||
event.respondWith((async () => {
|
||||
const cache = await caches.open(CACHE_NAME);
|
||||
|
||||
try {
|
||||
// Try to fetch the resource from the network.
|
||||
const fetchResponse = await fetch(event.request);
|
||||
|
||||
// Save the resource in the cache.
|
||||
cache.put(event.request, fetchResponse.clone());
|
||||
|
||||
// And return it.
|
||||
return fetchResponse;
|
||||
} catch (e) {
|
||||
// Fetching didn't work get the resource from the cache.
|
||||
const cachedResponse = await cache.match(event.request);
|
||||
|
||||
// And return it.
|
||||
return cachedResponse;
|
||||
}
|
||||
})());
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue