登记服务-工人
简化服务员注册的脚本,并配有通俗活动的钩子.
使用量
说明: 此脚本使用 ES 模块导出, 并且预计将与客户端侧捆绑器一起使用, 它可以处理 ES 模块语法 .
import { register } from 'register-service-worker'
register('/service-worker.js', {
registrationOptions: { scope: './' },
ready (registration) {
console.log('Service worker is active.')
},
registered (registration) {
console.log('Service worker has been registered.')
},
cached (registration) {
console.log('Content has been cached for offline use.')
},
updatefound (registration) {
console.log('New content is downloading.')
},
updated (registration) {
console.log('New content is available; please refresh.')
},
offline () {
console.log('No internet connection found. App is running in offline mode.')
},
error (error) {
console.error('Error during service worker registration:', error)
}
})
这个 ready, (中文(简体) ), registered, (中文(简体) ), cached, (中文(简体) ), updatefound 财务报告和审定财务报表 updated 事件通过a 服务工人注册 在他们的论点中.
这个 registrationOptions 对象将作为第二个参数传递到 ServiceWorkerContainer.register()