This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
The update
method of the ServiceWorkerRegistration
interface attempts to update the service worker. It fetches the worker's script URL, and if the new worker is not byte-by-byte identical to the current worker, it installs the new worker. The fetch of the worker bypasses any browser caches if the previous fetch occurred over 24 hours ago.
Note: This feature is available in Web Workers.
ServiceWorkerRegistration.update();
None.
Void.
The following simple example registers a service worker example, an then adds an event handler to a button so you can explicitly update the service worker whenever desired:
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); }); };
Specification | Status | Comment |
---|---|---|
Service Workers The definition of 'ServiceWorkerRegistration.update()' in that specification. | Editor's Draft | Initial definition. |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 45.0 [1] [2] | (Yes)[4] | 44.0 (44.0)[3] | No support | ? | No support |
Available in web workers | No support | ? | 44.0 (44.0)[3] | No support | ? | No support |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | ? | No support | 44.0 (44.0) | (Yes) | No support | ? | No support | 45.0 [1] [2] |
Available in web workers | ? | No support | (Yes) | ? | No support | ? | No support | 45.0 [1] [2] |
Promise
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/update