chore: fix sw.js error (#7667)

This commit is contained in:
iamkun 2022-05-12 23:48:16 +08:00 committed by GitHub
parent 591a7c32f3
commit ae25f4e14a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 1 deletions

View File

@ -67,6 +67,20 @@ export const head: HeadConfig[] = [
src: 'https://www.googletagmanager.com/gtag/js?id=UA-175337989-1',
},
],
[
'script',
{},
`if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('/sw.js')
.then(function(registration) {
console.log(registration);
})
.catch(function(err) {
console.log(err);
});
}`,
],
[
'script',
{

View File

@ -14,7 +14,6 @@ import VPSubNav from './vp-subnav.vue'
import VPSidebar from './vp-sidebar.vue'
import VPContent from './vp-content.vue'
import VPSponsors from './vp-sponsors.vue'
import VPReloadPrompt from './vp-reload-prompt.vue'
const USER_PREFER_GITHUB_PAGE = 'USER_PREFER_GITHUB_PAGE'
const [isSidebarOpen, toggleSidebar] = useToggle(false)

12
docs/public/sw.js Normal file
View File

@ -0,0 +1,12 @@
self.addEventListener('activate', (e) => {
e.waitUntil(
caches.keys().then((t) => {
return Promise.all(
t.map((n) => {
return caches.delete(n)
})
)
})
)
})
self.skipWaiting()