2023-02-09 20:29:07 +00:00
|
|
|
/* Service Worker */
|
|
|
|
|
2023-05-05 13:43:23 +01:00
|
|
|
const appVersion = '2.0.0-rc-20230505001'
|
2023-05-01 21:04:19 +01:00
|
|
|
const cacheName = `owlboard-${appVersion}`
|
|
|
|
const cacheIDs = [cacheName]
|
2023-05-04 10:21:42 +01:00
|
|
|
const staticCache = [
|
|
|
|
'/styles/fonts/firamono/firamono-500.woff2',
|
|
|
|
'/styles/fonts/firamono/firamono-regular.woff2',
|
|
|
|
'/styles/fonts/urwgothic/urwgothic.woff2',
|
|
|
|
'/styles/fonts/urwgothic/urwgothicDemi.woff2',
|
|
|
|
'/images/icon.svg',
|
|
|
|
'/images/logo/wide_logo.svg',
|
|
|
|
'/images/logo/mono-logo.svg',
|
|
|
|
'/images/app-icons/any/plain-logo.svg',
|
|
|
|
'/images/app-icons/any/plain-logo-512.png',
|
|
|
|
'/images/nav/alert_icon.svg',
|
|
|
|
'/images/nav/save.svg',
|
|
|
|
'/images/nav/home_icon.svg',
|
|
|
|
'/images/nav/back.svg',
|
|
|
|
'/images/nav/hamburger.svg',
|
|
|
|
'/images/nav/close.svg',
|
|
|
|
'/images/nav/refresh.svg',
|
|
|
|
'/images/nre/nre-powered_400w.webp',
|
|
|
|
'/images/nre/nre-powered_400w.jxl'
|
|
|
|
]
|
|
|
|
const dynamicCache = [
|
2023-05-01 21:04:19 +01:00
|
|
|
'/404.html',
|
|
|
|
'/auth.html',
|
|
|
|
'/board.html',
|
|
|
|
'/conn-err.html',
|
|
|
|
'/help.html',
|
|
|
|
'/',
|
|
|
|
'/issue.html',
|
|
|
|
'/find-code.html',
|
|
|
|
'/settings.html',
|
|
|
|
'/pis.html',
|
|
|
|
'/manifest.json',
|
|
|
|
'/styles/board.css',
|
|
|
|
'/styles/find-code.css',
|
|
|
|
'/styles/help.css',
|
|
|
|
'/styles/issue.css',
|
|
|
|
'/styles/main.css',
|
|
|
|
'/styles/settings.css',
|
|
|
|
'/styles/pis.css',
|
|
|
|
'/js/find-code.js',
|
|
|
|
'/js/index.js',
|
|
|
|
'/js/issue.js',
|
|
|
|
'/js/lib.board.js',
|
|
|
|
'/js/lib.main.js',
|
|
|
|
'/js/auth.js',
|
|
|
|
'/js/settings.js',
|
|
|
|
'/js/simple-board.js',
|
2023-05-04 10:21:42 +01:00
|
|
|
'/js/pis.js'
|
2023-05-01 21:04:19 +01:00
|
|
|
]
|
2023-02-09 20:29:07 +00:00
|
|
|
|
2023-05-04 10:21:42 +01:00
|
|
|
for(let i = 0; i < dynamicCache.length; i++) {
|
|
|
|
let item = dynamicCache[i] + `?${appVersion}`
|
|
|
|
staticCache.push(item)
|
|
|
|
}
|
|
|
|
|
2023-05-01 21:04:19 +01:00
|
|
|
self.addEventListener('install', (e) => {
|
|
|
|
console.log('[Service Worker] Install')
|
|
|
|
e.waitUntil(
|
|
|
|
(async () => {
|
|
|
|
const cache = await caches.open(cacheName)
|
|
|
|
console.log('[Service Worker] Caching app data')
|
2023-05-04 10:21:42 +01:00
|
|
|
await cache.addAll(staticCache)
|
2023-05-01 21:04:19 +01:00
|
|
|
})()
|
|
|
|
)
|
|
|
|
})
|
2023-02-09 20:29:07 +00:00
|
|
|
|
2023-05-01 21:04:19 +01:00
|
|
|
self.addEventListener('fetch', (e) => {
|
2023-03-01 11:38:31 +00:00
|
|
|
e.respondWith(
|
|
|
|
(async () => {
|
2023-05-01 21:04:19 +01:00
|
|
|
const r = await caches.match(e.request,{ignoreSearch: true})
|
2023-03-01 11:38:31 +00:00
|
|
|
if (r) {
|
2023-05-01 21:04:19 +01:00
|
|
|
return r
|
2023-03-01 11:38:31 +00:00
|
|
|
}
|
2023-05-01 21:04:19 +01:00
|
|
|
const response = await fetch(e.request)
|
|
|
|
console.log(`[Service Worker] Not cached - fetching from server: ${e.request.url}`)
|
|
|
|
return response
|
2023-03-01 11:38:31 +00:00
|
|
|
})()
|
2023-05-01 21:04:19 +01:00
|
|
|
)
|
|
|
|
})
|
2023-02-09 20:29:07 +00:00
|
|
|
|
2023-03-01 11:38:31 +00:00
|
|
|
self.addEventListener('activate', function (event) {
|
|
|
|
event.waitUntil(caches.keys().then(function (keys) {
|
|
|
|
return Promise.all(keys.filter(function (key) {
|
2023-05-01 21:04:19 +01:00
|
|
|
return !cacheIDs.includes(key)
|
2023-03-01 11:38:31 +00:00
|
|
|
}).map(function (key) {
|
2023-05-01 21:04:19 +01:00
|
|
|
return caches.delete(key)
|
|
|
|
}))
|
2023-03-01 11:38:31 +00:00
|
|
|
}).then(function () {
|
2023-05-01 21:04:19 +01:00
|
|
|
return self.clients.claim()
|
|
|
|
}))
|
|
|
|
})
|