navigator.serviceWorker is never ready

喜你入骨 提交于 2019-11-30 05:38:05

The problem was that the service-worker.js file was stored in an assets sub-directory.

Don't do that: store the service-worker.js in the root of your app (or higher). That way your app can access the service-worker.

See HTML5Rocks article --

One subtlety with the register method is the location of the service worker file. You'll notice in this case that the service worker file is at the root of the domain. This means that the service worker's scope will be the entire origin. In other words, this service worker will receive fetch events for everything on this domain. If we register the service worker file at /example/sw.js, then the service worker would only see fetch events for pages whose URL starts with /example/ (i.e. /example/page1/, /example/page2/).

Added

A new problem is that the serviceworker is never ready if the page is hard-reloaded. Subsequent soft page reloads work fine. Google's own sample code fails. See the Chrome bug report.

The bug fix was included with Chrome 44.

In my case - simply close the tab and open it again...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!