add primitive cache busting, update service worker
This commit is contained in:
parent
4b7000e8f4
commit
e4200690d9
|
@ -223,9 +223,29 @@
|
|||
setTimeout(() => {
|
||||
setServiceWorkerStatus('')
|
||||
}, 4500)
|
||||
|
||||
registration.addEventListener('updatefound', () => {
|
||||
console.info('Service worker will be updated...')
|
||||
const newWorker = registration.installing
|
||||
|
||||
newWorker.addEventListener('statechange', () => {
|
||||
if (newWorker.state === 'installed') {
|
||||
newWorker.postMessage({ action: 'skipWaiting' })
|
||||
}
|
||||
})
|
||||
})
|
||||
}).catch((err) => {
|
||||
setServiceWorkerStatus(`Service worker error: ${err.toString()}`)
|
||||
})
|
||||
|
||||
let refreshing
|
||||
serviceWorker.addEventListener('controllerchange', () => {
|
||||
if (refreshing) {
|
||||
return
|
||||
}
|
||||
window.location.reload()
|
||||
refreshing = true
|
||||
})
|
||||
}
|
||||
|
||||
if (!noJS()) {
|
||||
|
|
|
@ -1,9 +1,13 @@
|
|||
// Worker v1
|
||||
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open('fb-to-ical').then((cache) => {
|
||||
return cache.addAll([
|
||||
'/',
|
||||
'/favicon.ico',
|
||||
'/scripts.js?1',
|
||||
'/style.css?1',
|
||||
])
|
||||
})
|
||||
)
|
||||
|
@ -17,3 +21,9 @@ self.addEventListener('fetch', (event) => {
|
|||
})
|
||||
)
|
||||
})
|
||||
|
||||
self.addEventListener('message', (event) => {
|
||||
if (event.data.action === 'skipWaiting') {
|
||||
self.skipWaiting()
|
||||
}
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="manifest" href="/manifest.json">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="/icon-180.png">
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
<link rel="stylesheet" type="text/css" href="/style.css?1">
|
||||
<title>Facebook Event to iCal Converter</title>
|
||||
</head>
|
||||
|
||||
|
@ -71,6 +71,6 @@
|
|||
Created by <a href="http://ondrejsynacek.com">Ondrej Synacek</a>
|
||||
</footer>
|
||||
|
||||
<script src="/scripts.js"></script>
|
||||
<script src="/scripts.js?1"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
Loading…
Reference in New Issue