feat: add PWA support

This commit is contained in:
jianjian.ma 2023-03-27 18:02:35 +08:00
parent 689b7bab26
commit 5593c067c4
3 changed files with 11 additions and 13 deletions

View File

@ -50,7 +50,7 @@ export default function RootLayout({
href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;700;900&display=swap"
rel="stylesheet"
></link>
<script src="/serviceWorker.js" async></script>
<script src="/serviceWorkerRegister.js" defer></script>
</head>
<body>{children}</body>
</html>

View File

@ -9,7 +9,6 @@ self.addEventListener('install', function (event) {
caches.open(CHATGPT_NEXT_WEB_CACHE)
.then(function (cache) {
return cache.addAll([
'/',
]);
})
);
@ -22,14 +21,4 @@ self.addEventListener('fetch', function (event) {
return response || fetch(event.request);
})
);
});
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
console.error('ServiceWorker registration failed: ', err);
});
});
}
});

View File

@ -0,0 +1,9 @@
if ('serviceWorker' in navigator) {
window.addEventListener('load', function () {
navigator.serviceWorker.register('/serviceWorker.js').then(function (registration) {
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function (err) {
console.error('ServiceWorker registration failed: ', err);
});
});
}