This repository was archived by the owner on Jan 11, 2023. It is now read-only.
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Support callback for Service worker registration #744
Open
Description
According to The Service Worker Lifecycle, Sapper (without push/sync) seems to never trigger an update.
I see that the service worker script is injected directly making it hard to customize the callback.
I am trying to build a "version check" thing. I customized the service worker to handle some of the stuff but since I do not have the callback/promise to work with, it's tough to trigger this without modifying the sapper base to something like this:
if (has_service_worker) {
script += `if('serviceWorker' in navigator)navigator.serviceWorker.register('${req.baseUrl}/service-worker.js').then(reg => {
setInterval(() => {
console.log('checking sw update');
reg.update()
}, 3600000);
});`;
}
One other way could be is to remove the hard check on has_service_worker and allow users to write their own implementation.
Let me know if it makes sense.