-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5dc4390
commit b5d5ed1
Showing
1 changed file
with
52 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,52 @@ | ||
self.addEventListener('install', (e) => { | ||
e.waitUntil( | ||
caches.open('iDSandbox4All').then((cache) => cache.addAll([ | ||
'/id_sandbox_for_all/', | ||
'/id_sandbox_for_all/index.html', | ||
'/id_sandbox_for_all/land.html', | ||
'/id_sandbox_for_all/icon/icon.png', | ||
'/id_sandbox_for_all/dist/iD.js', | ||
'/id_sandbox_for_all/dist/iD.css', | ||
])), | ||
); | ||
}); | ||
|
||
self.addEventListener('fetch', (e) => { | ||
console.log(e.request.url); | ||
e.respondWith( | ||
caches.match(e.request).then((response) => response || fetch(e.request)), | ||
); | ||
}); | ||
var GHPATH = '/github-page-pwa'; | ||
var APP_PREFIX = 'gppwa_'; | ||
var VERSION = 'version_002'; | ||
var URLS = [ | ||
`${GHPATH}/`, | ||
`${GHPATH}/index.html`, | ||
`${GHPATH}/css/styles.css`, | ||
`${GHPATH}/img/icon.png`, | ||
`${GHPATH}/js/app.js` | ||
] | ||
|
||
var CACHE_NAME = APP_PREFIX + VERSION | ||
self.addEventListener('fetch', function (e) { | ||
console.log('Fetch request : ' + e.request.url); | ||
e.respondWith( | ||
caches.match(e.request).then(function (request) { | ||
if (request) { | ||
console.log('Responding with cache : ' + e.request.url); | ||
return request | ||
} else { | ||
console.log('File is not cached, fetching : ' + e.request.url); | ||
return fetch(e.request) | ||
} | ||
}) | ||
) | ||
}) | ||
|
||
self.addEventListener('install', function (e) { | ||
e.waitUntil( | ||
caches.open(CACHE_NAME).then(function (cache) { | ||
console.log('Installing cache : ' + CACHE_NAME); | ||
return cache.addAll(URLS) | ||
}) | ||
) | ||
}) | ||
|
||
self.addEventListener('activate', function (e) { | ||
e.waitUntil( | ||
caches.keys().then(function (keyList) { | ||
var cacheWhitelist = keyList.filter(function (key) { | ||
return key.indexOf(APP_PREFIX) | ||
}) | ||
cacheWhitelist.push(CACHE_NAME); | ||
return Promise.all(keyList.map(function (key, i) { | ||
if (cacheWhitelist.indexOf(key) === -1) { | ||
console.log('Deleting cache : ' + keyList[i] ); | ||
return caches.delete(keyList[i]) | ||
} | ||
})) | ||
}) | ||
) | ||
}) |