vail/static/sw.js

30 lines
527 B
JavaScript
Raw Normal View History

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) {
let fetchInit = {}
2021-04-28 10:17:23 -06:00
if (event.request.url.match(/\.(css|mjs|js|html)$/)) {
fetchInit.cache = "no-cache"
}
2021-04-27 12:42:06 -06:00
event.respondWith(
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
}