You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
//index.jsif("serviceWorker"innavigator){// Use the window load event to keep the page load performantwindow.addEventListener("load",()=>{navigator.serviceWorker.register("/service-worker.js").then(registration=>{console.log("register succces...")},err=>{console.log("register error...",err)});});}
service-worker进程
//service-worker.jsconsole.log('Hello from service-worker.js');
主进程
service-worker进程
在service-worker中可以定义监听事件,然后在对应事件中进行逻辑处理。
具体api可查看 service worker MDN
service-worker进程的执行流程
除了 install之外,还有 activate,message,fetch,sync,push等事件。
打开chrome浏览器的
application->service workers
,会看到image
可以看到status为 actived and is running,表明service-worker已经安装成功了。
在service-worker中通过监听事件,然后编写对应的逻辑并不是一件容易的事,尤其对于文件缓存,可能npm run build后,名称随时会变。
所以chrome官方推出了wokbox框架
clipboard.png
wokbox 是用于向web应用程序添加离线支持的JavaScript库。
The text was updated successfully, but these errors were encountered: