always show loading

This commit is contained in:
Pooya Parsa 2020-11-04 00:52:23 +01:00
parent 2f329dec26
commit 10fddd223e

View File

@ -1,6 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<link rel="prefetch" href="/nuxt.sw.js"> <link rel="prefetch" href="/nuxt.sw.js">
@ -9,24 +8,16 @@
if (!('serviceWorker' in navigator)) { if (!('serviceWorker' in navigator)) {
throw new Error('Browser not supported!') throw new Error('Browser not supported!')
} }
let timeout
const stopTimer = () => { if (timeout) { clearTimeout(timeout); timeout = undefined } }
const startTimer = () => { stopTimer(); timeout = setTimeout(() => { document.write('Loading...') }, 3000) }
startTimer()
navigator.serviceWorker.register('/nuxt.sw.js').then((registration) => { navigator.serviceWorker.register('/nuxt.sw.js').then((registration) => {
stopTimer()
console.log('ServiceWorker registration successful with scope:', registration.scope) console.log('ServiceWorker registration successful with scope:', registration.scope)
window.location.reload(false) window.location.reload(false)
}).catch(error => { }).catch(error => {
stopTimer()
console.error('ServiceWorker registration failed:', error) console.error('ServiceWorker registration failed:', error)
document.write(error) document.write(error)
}) })
</script> </script>
</head> </head>
<body>
<body></body> Loading...
</body>
</html> </html>