Service worker file not found in offline mode

末鹿安然 提交于 2019-12-22 18:37:35

问题


My web app is like this:

I have an Apache server running on port 80, with virtual hosts for my domain and different subdomains, including port 443 for SSL.

I have a nodejs application running on port 5000.

All traffic to my main domain is redirected using proxypass from apache to nodejs.

NodeJs then loads Service Workers.

Problem:

ON first load of application in online mode it works properly.Shows Service worker registered over the complete domain message as expected. Even for some css,js and img it return response fromServiceWorker.

But now when I open same page on offline mode service worker dont play it part to open the web app.

Error: 1. Uncaught (in promise) TypeError: Failed to fetch(…).

  1. An unknown error occurred when fetching the script for service-worker file.

Any help on this regard to implement this properly will be be helpful.


回答1:


Your browser will attempt to refetch the JavaScript file corresponding to the current service worker for every navigation request. You can read more about that in this Stack Overflow answer.

What you're seeing logged reflects the fact that the JavaScript for your service worker can't be fetch (which makes sense, because you're offline). What happens in that case is that the previous JavaScript that your browser already knows about and has cached will be reused, and your service worker should function as expected. The noise in the DevTools console about the service worker's JavaScript failing to be fetched can be ignored.

If you're seeing any failures related to the actual function of the service worker itself (like, retrieving cached resources are failing), then that would point to an issue with your implementation. But it doesn't sound like that's what's being logged.




回答2:


Make sure the html files are cached, and that the service worker script is in the top level.



来源:https://stackoverflow.com/questions/39418740/service-worker-file-not-found-in-offline-mode

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