cordova app上的服务人员 [英] Service workers on cordova app

查看:456
本文介绍了cordova app上的服务人员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在Android设备上运行的混合应用程序(离子1 / cordova)中使用服务工作者吗?我试图在Android设备上运行的离子应用程序上安装服务工作程序时遇到一些错误,因为android使用文件协议来提供文件,而服务工作者要求文件由HTTPS协议或http(仅用于localhost)提供服务:

Can i use service workers inside hybrids apps(ionic 1/cordova) running on android devices? I'm getting some errors when trying to install a service worker on ionic app running on android device, because android uses file protocol to serve files and service-workers require files to be served by HTTPS protocol or http(only for localhost):


服务工作者注册期间出错:DOMException:无法
注册ServiceWorker:当前来源的URL协议
('file://')不受支持。

Error during service worker registration: DOMException: Failed to register a ServiceWorker: The URL protocol of the current origin ('file://') is not supported.

这不是在移动浏览器上运行的传统渐进式Web应用程序,而是在Android设备上(webview + cordova)。

It's not a traditional progressive web application running on mobile browser, but instead on android device (webview + cordova).

我需要实现这一点,以便在我的api调用中利用我的应用程序缓存策略(使用来自谷歌的sw-precache e sw-toolbox)。

I need achieve that to leverage my app with cache strategies(using sw-precache e sw-toolbox from google) on my api calls.

推荐答案

实际上,根据 caniuse ,它得到支持。问题在于使用的协议。

Actually, according to caniuse, it is supported. The issue is with the protocol used.

如果您阅读服务工作者,您将在先决条件中看到生产中您需要使用 HTTPS

If you read on Service Workers, you will see in prerequisites that in production you are required to use HTTPS.

使用Crosswalk可能会有所帮助,请看一下 XWALK-5919

Using Crosswalk might help though, take a look at XWALK-5919.

这篇关于cordova app上的服务人员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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