在脱机模式下找不到服务工作文件 [英] Service worker file not found in offline mode

查看:119
本文介绍了在脱机模式下找不到服务工作文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络应用程序是这样的:

My web app is like this:

我有一个在端口80上运行的Apache服务器,我的域和不同子域的虚拟主机,包括SSL的端口443 。

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

我在端口5000上运行了一个nodejs应用程序。

I have a nodejs application running on port 5000.

我的主域名的所有流量都被重定向从apache到nodejs的proxypass。

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

NodeJ然后加载服务工作者。

NodeJs then loads Service Workers.

问题:

在线模式下第一次加载应用程序时,它正常工作.Shows服务工作者按预期在整个域消息上注册。即使对于某些css,js和img,它也会从ServiceWorker返回响应。

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.

错误:
1.未捕获(承诺)TypeError:无法获取(...)。

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


  1. 获取service-worker文件的脚本时发生未知错误。

这方面的任何帮助都是正确实现这一点的。很有帮助。

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

推荐答案

您的浏览器将尝试为每个导航请求重新获取与当前服务工作者相对应的JavaScript文件。您可以在此Stack Overflow答案中阅读更多相关信息。

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.

您所看到的内容记录反映了您的服务工作者的JavaScript无法获取的事实(这是有道理的,因为您处于脱机状态)。在这种情况下会发生的情况是,您的浏览器已经知道并缓存的先前JavaScript将被重用,您的服务工作者应该按预期运行。可以忽略DevTools控制台中关于服务工作者未能获取的JavaScript的噪音。

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.

这篇关于在脱机模式下找不到服务工作文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆