Adjust old sw.js file to remove itself, allowing new service-worker.js to be activated

This commit is contained in:
Fred Boniface 2023-07-12 00:50:01 +01:00
parent 543318dd8a
commit ada17c4ba0
2 changed files with 19 additions and 1 deletions

16
static/sw.js Normal file
View File

@ -0,0 +1,16 @@
// Remove the service worker /sw.js from legacy installations
// This should then enable the new /service-worker.js to be installed
self.addEventListener('activate', function (e) {
console.log(`Unregistering service worker`)
self.registration.unregister()
.then(function () {
return self.clients.matchAll();
})
.then(function (clients) {
clients.forEach(client => {
console.log(`Navigating ${client.url}`)
client.navigate(client.url)
})
});
});

View File

@ -1,6 +1,6 @@
import adapter from '@sveltejs/adapter-static'; import adapter from '@sveltejs/adapter-static';
export default { const config = {
kit: { kit: {
adapter: adapter({ adapter: adapter({
pages: 'build', pages: 'build',
@ -11,3 +11,5 @@ export default {
}) })
} }
}; };
export default config;