修改Cordova插件的加载行为以加快加载时间 [英] Modify Cordova Plugin loading behaviour to speed up load time

查看:42
本文介绍了修改Cordova插件的加载行为以加快加载时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种加快在Cordova上加载插件的方法,以便可以尽早显示我的UI(UI并不需要在首次启动时严格要求所有插件).

I am looking for a way to speed up plugin loading on Cordova so I can show up my UI at the earliest (the UI does not have a strict need of all plugins on first launch).

到目前为止我尝试过的事情:

What I have tried so far:

  • 根据文档,我尝试添加:< param name ="onload" value ="false"/> ;我正在加载的每个功能.无济于事.(有关SO的相关查询)

  • As per the documentation, I have tried adding: <param name="onload" value="false" />; for every feature that I am loading. Does not help. (Related query on SO)

已将应用初始化代码从 deviceReady 中移出(初始化不需要Cordova特定位).

Have moved app initialization code out of deviceReady (the initialization does not require Cordova specific bits).

我如何得出插件是瓶颈的结论?如下:

How I came to the conclusion that plugins are a bottleneck? As follows:

  • 我卸载了该应用程序所需的所有插件(其中有23个!),加载时间缩短了2.5到3秒.因此,我确信这是一个瓶颈.

  • I uninstalled all the plugins that the app needed (23 of them!) and the load time was shaved off by 2.5 to 3 seconds. So I am sure that this is a bottleneck.

我还删除了所有的JS和CSS,包括cordova.js,并加载了空白的HTML页面.有插件和无插件.差别很大.

Also, I removed all JS and CSS, including cordova.js and loaded a blank HTML page. With plugins and without plugins. The difference was huge.

总的来说,问题是,在所有插件的本机代码未运行之前,WebView本身不会出现.插件越多,可见的时间就越多.有什么方法可以让Cordova立即加载WebView并让JS加载,同时它在后台初始化插件并在需要时触发 deviceReady ?我可以稍后再做Cordova特定的事情.

Overall the issue is that until all the native code of plugins has not run, the WebView itself does not appear. More the plugins, more the time it takes to be visible. Is there any way to let Cordova load WebView immediately and let the JS load while it initializes the plugins in the background and fires deviceReadywhenever it has to? I can do Cordova specific things at a later point of time.

相关:

  1. 在加载API之前在Cordova中显示webView
  2. phonegap插件onload = false无效

推荐答案

我很同情您的目标,但您不能从萝卜.

I empathize with your goal, but you cannot get milk from a turnip.

出于使用 onload = false 的想法,已不推荐使用< feature(...)> .按照底部的链接,并阅读#12.

With the idea of using onload=false, the <feature (...)> has been deprecated. Follow the link at the bottom, and read #12.

在另一个问题上,很明显,提出问题的人并不知道这是不可能的.

On the other question, it is apparent that the persons asking questions does not have the knowledge to know that this is not possible.

所有Cordova/Phonegap平台的主要UI查看器是一个称为WebView的库(在Android中,以及其他平台上的类似库,

The main UI viewer for all Cordova/Phonegap platforms is a library called WebView (in Android, and similar on other platforms, see) All these libraries have one thing in common, the do NOT load, Javascript, or another tools that would make it a full-blown webbrowser. As a result, Javascript must be enable (by Cordova) and loaded (by the OS). This does not happen until all the other portions of the HTML document are recognize (but perhaps not loaded); this includes CSS, fonts, images and icons (if needed).

但是,在后面的项目(例如CSS)上,可以弥补时间-如果对CSS进行了优化.很多时候,开发人员由于需要交付一个里程碑而没有进行此优化(他们通常从不回去修复它).

However, on the later items, CSS for instance, time can be made up - if the CSS is optimized. Many times developers do not do this optimization, because of a need to deliver a milestone (and they often never return to fix it).

回到插件,确实需要一些时间来加载插件,但是通常不清楚为什么插件要花这么长时间.加载后的插件确实必须进行一些初始化,但是要花多长时间取决于插件.例如,地理位置(GPS)插件可能需要长达10秒钟的时间才能获得可用的读数.

Returning to the plugins, it is true that some time is needed to load the plugins, but it is often not clear why the plugins are taking soo long. Plugins after loading do have to do *some* initialization, but how long it takes depends on the plugin. For instance, the geolocation (GPS) plugin can take as long as 10 seconds before a usable reading is available.

  • 加载时间很难调整加载时间,因为无论插件如何,插件都需要加载所需的内容.
  • 初始化时间尝试调整插件的内部是与作者进行的讨论.
  • load time Trying to tweak the load time will hardly prove useful, because regardless of the plugin, the plugin needs to load what it needs.
  • init time Trying to tweak the internals of the plugin is a discussion you should have with the author.

此外,我可以推测为什么某些插件要花这么长时间,但是我不知道您在使用哪个插件.所以这是徒劳的.

Also, I could speculate as to why some of the plugins are taking so long, but I don't know which you are using; so this would be a futile effort.

最后,也许*有一些方法可以缩短启动用户就绪之间的时间,但是我没有听说过,也没有看到.这包括我对Cordova,Phonegap,Android和Apple的iOS文档的阅读.

Lastly, there *maybe* some method to reduce the time between, launch and user-ready, but I have heard of none, and I have seen none. This includes my readings of Cordova, Phonegap, Android and Apple's iOS docs.

在开发过程中,本文档可能会很有用
Cordova/Phonegap新手开发人员的主要错误

This document may prove useful while you are developing
Top Mistakes by Developers new to Cordova/Phonegap

这篇关于修改Cordova插件的加载行为以加快加载时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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