mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
fast replace instead of reload
This commit is contained in:
parent
10fddd223e
commit
885f0aba66
@ -1,23 +1,38 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
|
|
||||||
<head>
|
<head>
|
||||||
|
<!-- SW_INIT-->
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link rel="prefetch" href="/nuxt.sw.js">
|
<link rel="prefetch" href="/nuxt.sw.js">
|
||||||
<link rel="preload" href="/nuxt.sw.js" as="worker">
|
|
||||||
<script>
|
<script>
|
||||||
if (!('serviceWorker' in navigator)) {
|
async function reload() {
|
||||||
throw new Error('Browser not supported!')
|
const html = await fetch(window.location.href).then(r => r.text())
|
||||||
|
if (html.includes('<!-- SW_INIT-->')) {
|
||||||
|
window.location.reload(false)
|
||||||
|
} else {
|
||||||
|
document.open()
|
||||||
|
document.write(html)
|
||||||
|
document.close()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
navigator.serviceWorker.register('/nuxt.sw.js').then((registration) => {
|
|
||||||
console.log('ServiceWorker registration successful with scope:', registration.scope)
|
async function register() {
|
||||||
window.location.reload(false)
|
const registration = await navigator.serviceWorker.register('/nuxt.sw.js')
|
||||||
}).catch(error => {
|
await navigator.serviceWorker.ready
|
||||||
console.error('ServiceWorker registration failed:', error)
|
registration.active.addEventListener('statechange', (event) => {
|
||||||
document.write(error)
|
if (event.target.state === 'activated') {
|
||||||
})
|
reload()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
register()
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
Loading...
|
Loading...
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
Reference in New Issue
Block a user