How can I programmatically update service worker since ServiceWorkerRegistration.update()
has not been implemented in Chrome yet? Is there an alternative?
Asked
Active
Viewed 3,872 times
4

try-catch-finally
- 7,436
- 6
- 46
- 67

Lewis
- 14,132
- 12
- 66
- 87
3 Answers
6
I assume you got this by now but I think you want serviceWorker.skipWaiting()

David
- 2,846
- 3
- 22
- 34
-
1The OP might have found their answer but it's good to have a record for someone who might search in the future. Thanks for writing this. – RJHunter Oct 07 '16 at 23:33
1
From the spec.
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw-test/sw.js', {scope: 'sw-test'}).then(function(registration) {
// registration worked
console.log('Registration succeeded.');
button.onclick = function() {
registration.update();
}
}).catch(function(error) {
// registration failed
console.log('Registration failed with ' + error);
});
};

Sten Muchow
- 6,623
- 4
- 36
- 46
0
Thr best workaround seems to be to force update by changing checksum of the service worker file by some simple backend code (it can be like last commented line with microtime), which will be detected by browser

Karol Klepacki
- 2,070
- 1
- 18
- 30