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.
Syntax
serviceWorkerRegistration.update();
Parameters
None.
Return value
A Promise
that resolves with a ServiceWorkerRegistration
object.
Example
The following simple example registers a service worker example 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); }); };
Specifications
Specification | Status | Comment |
---|---|---|
Service Workers The definition of 'ServiceWorkerRegistration.update()' in that specification. |
Working Draft | Initial definition. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
update | Chrome
Full support
45
| Edge
Full support
17
| Firefox
Full support
44
| IE No support No | Opera
Full support
32
| Safari Full support 11.1 | WebView Android
Full support
45
| Chrome Android
Full support
45
| Firefox Android Full support 44 | Opera Android
Full support
32
| Safari iOS No support No | Samsung Internet Android
Full support
4.0
|
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
- Experimental. Expect behavior to change in the future.
- See implementation notes.
- See implementation notes.
- User must explicitly enable this feature.
- User must explicitly enable this feature.