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

View File

@ -9,7 +9,6 @@ self.addEventListener('install', function (event) {
caches.open(CHATGPT_NEXT_WEB_CACHE) caches.open(CHATGPT_NEXT_WEB_CACHE)
.then(function (cache) { .then(function (cache) {
return cache.addAll([ return cache.addAll([
'/',
]); ]);
}) })
); );
@ -23,13 +22,3 @@ self.addEventListener('fetch', function (event) {
}) })
); );
}); });
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);
});
});
}