简单开启服务工作线程是怎么开启的
//子线程navigatorWorker.js
console.log('服务工作线程注册成功');
self.addEventListener('install',function(e){console.log('install事件已经开启');
})
//主线程
//index.html
<!DOCTYPE html>
<html><head><meta http-equiv="content" content="text/html;charset=UTF-8"/><title>测试服务工作者线程</title></head><body><script>if('serviceWorker' in navigator){//注册服务工作线程;scope表示手动指定作用域范围navigator.serviceWorker.register('navigatorWorker.js',{scope:'/a'}).then((res)=>{//这里返回的期约是navigatorWorkerRegistration对象console.log('Service Wroker:',res);}).catch((error)=>{console.log('service worker注册失败',error);})}</script></body>
</html>