2021-04-27 12:42:06 -06:00
|
|
|
cacheName = "v1"
|
2020-05-26 20:52:48 -06:00
|
|
|
|
2021-04-27 12:42:06 -06:00
|
|
|
self.addEventListener("install", e => install(e))
|
2020-05-26 20:52:48 -06:00
|
|
|
function install(event) {
|
2021-04-27 12:42:06 -06:00
|
|
|
event.waitUntil(
|
|
|
|
caches.open(cacheName)
|
|
|
|
.then(cache => {
|
|
|
|
return cache.addAll(
|
|
|
|
[
|
|
|
|
"/",
|
|
|
|
]
|
|
|
|
)
|
|
|
|
})
|
|
|
|
)
|
2020-05-26 20:52:48 -06:00
|
|
|
}
|
|
|
|
|
2021-04-27 12:42:06 -06:00
|
|
|
self.addEventListener("fetch", e => cacheFetch(e))
|
|
|
|
function cacheFetch(event) {
|
2021-04-27 19:35:39 -06:00
|
|
|
let fetchInit = {}
|
2021-04-28 10:17:23 -06:00
|
|
|
if (event.request.url.match(/\.(css|mjs|js|html)$/)) {
|
2021-04-27 19:35:39 -06:00
|
|
|
fetchInit.cache = "no-cache"
|
|
|
|
}
|
2021-04-27 12:42:06 -06:00
|
|
|
event.respondWith(
|
2021-04-27 19:35:39 -06:00
|
|
|
fetch(event.request, fetchInit)
|
2021-04-27 12:42:06 -06:00
|
|
|
.catch(() => {
|
|
|
|
return caches.match(event.request)
|
|
|
|
})
|
|
|
|
)
|
2020-05-26 20:52:48 -06:00
|
|
|
}
|