update()
方法在
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.
注意 : This feature is available in Web 工作者 .
serviceWorkerRegistration.update();
None.
A
Promise
that resolves with a
ServiceWorkerRegistration
对象。
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);
});
};
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'ServiceWorkerRegistration.update()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
update
|
Chrome
45
|
Edge
17
|
Firefox
44
|
IE No |
Opera
32
|
Safari 11.1 |
WebView Android
45
|
Chrome Android
45
|
Firefox Android 44 |
Opera Android
32
|
Safari iOS No |
Samsung Internet Android
4.0
|
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
用户必须明确启用此特征。
ServiceWorkerRegistration