简体   繁体   中英

Service worker file not found in offline mode

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.

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.

确保缓存html文件,并确保服务工作者脚本位于顶层。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM