ServiceWorkerRegistration.update() - Web APIs 编辑
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
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论