Skip to content

Commit

Permalink
更新serviceworker逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
lloydzhou committed Jul 16, 2024
1 parent 4b84fb3 commit eb7c7cd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions public/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ self.addEventListener("activate", function (event) {
});

self.addEventListener("install", function (event) {
self.skipWaiting(); // 立即启用新的版本
event.waitUntil(
caches.open(CHATGPT_NEXT_WEB_CACHE).then(function (cache) {
return cache.addAll([]);
Expand Down
9 changes: 8 additions & 1 deletion public/serviceWorkerRegister.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ 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);
registration.update().then(res => {
console.log('ServiceWorker registration update: ', res);
});
}, function (err) {
console.error('ServiceWorker registration failed: ', err);
});
navigator.serviceWorker.addEventListener('controllerchange', function() {
console.log('ServiceWorker controllerchange ');
window.location.reload(true);
});
});
}
}

0 comments on commit eb7c7cd

Please sign in to comment.