aboutsummaryrefslogtreecommitdiff
path: root/sw.js
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2021-02-06 14:10:00 +0100
committerJakob Stendahl <jakob.stendahl@outlook.com>2021-02-06 14:10:00 +0100
commitb07c2d6792174c9132679671ea7dae77c87349d9 (patch)
tree06c534166d24f3c426a7dff9aa1cbce2e1cfd639 /sw.js
parent34a24733ef7159105ab162f870b96e9649bc5c34 (diff)
downloadhoverbit-ble-b07c2d6792174c9132679671ea7dae77c87349d9.tar.gz
hoverbit-ble-b07c2d6792174c9132679671ea7dae77c87349d9.zip
Use parcel, add features
Diffstat (limited to 'sw.js')
-rw-r--r--sw.js61
1 files changed, 0 insertions, 61 deletions
diff --git a/sw.js b/sw.js
deleted file mode 100644
index bc3f42d..0000000
--- a/sw.js
+++ /dev/null
@@ -1,61 +0,0 @@
-var APP_PREFIX = 'hoverbitcontroller' // Identifier for this app (this needs to be consistent across every cache update)
-var VERSION = 'version_01' // Version of the off-line cache (change this value everytime you want to update cache)
-var CACHE_NAME = APP_PREFIX + VERSION
-var URLS = [ // Add URL you want to cache in this list.
- '/hoverbit-ble/', // If you have separate JS/CSS files,
- '/hoverbit-ble/index.html', // add path to those files here
- '/hoverbit-ble/styles.css',
- '/hoverbit-ble/microbit.umd.js',
- '/hoverbit-ble/script.js'
-]
-
-// Respond with cached resources
-self.addEventListener('fetch', function (e) {
- console.log('fetch request : ' + e.request.url)
- e.respondWith(
- caches.match(e.request).then(function (request) {
- if (request) { // if cache is available, respond with cache
- console.log('responding with cache : ' + e.request.url)
- return request
- } else { // if there are no cache, try fetching request
- console.log('file is not cached, fetching : ' + e.request.url)
- return fetch(e.request)
- }
-
- // You can omit if/else for console.log & put one line below like this too.
- // return request || fetch(e.request)
- })
- )
-})
-
-// Cache resources
-self.addEventListener('install', function (e) {
- e.waitUntil(
- caches.open(CACHE_NAME).then(function (cache) {
- console.log('installing cache : ' + CACHE_NAME)
- return cache.addAll(URLS)
- })
- )
-})
-
-// Delete outdated caches
-self.addEventListener('activate', function (e) {
- e.waitUntil(
- caches.keys().then(function (keyList) {
- // `keyList` contains all cache names under your username.github.io
- // filter out ones that has this app prefix to create white list
- var cacheWhitelist = keyList.filter(function (key) {
- return key.indexOf(APP_PREFIX)
- })
- // add current cache name to white list
- 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])
- }
- }))
- })
- )
-})