简体   繁体   English

修改Cordova插件加载行为以加快加载时间

[英]Modify Cordova Plugin loading behaviour to speed up load time

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). 我正在寻找一种方法来加快Cordova上的插件加载,所以我可以最早显示我的UI(UI在第一次启动时没有严格需要所有插件)。

What I have tried so far: 到目前为止我尝试了什么:

  • As per the documentation, I have tried adding: <param name="onload" value="false" /> ; 根据文档,我尝试添加: <param name="onload" value="false" /> ; for every feature that I am loading. 对于我正在加载的每个功能。 Does not help. 没有帮助。 ( Related query on SO ) 关于SO的相关查询

  • Have moved app initialization code out of deviceReady (the initialization does not require Cordova specific bits). 已将app初始化代码移出deviceReady (初始化不需要Cordova特定位)。

How I came to the conclusion that plugins are a bottleneck? 我是如何得出插件是瓶颈的结论? As follows: 如下:

  • 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. 我卸载了应用程序所需的所有插件(其中23个!),加载时间缩短了2.5到3秒。 So I am sure that this is a bottleneck. 所以我确信这是一个瓶颈。

  • Also, I removed all JS and CSS, including cordova.js and loaded a blank HTML page. 此外,我删除了所有JS和CSS,包括cordova.js并加载了一个空白的HTML页面。 With plugins and without plugins. 有插件和没有插件。 The difference was huge. 差异很大。

Overall the issue is that until all the native code of plugins has not run, the WebView itself does not appear. 总的来说问题是,在插件的所有本机代码都没有运行之前,WebView本身不会出现。 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 deviceReady whenever it has to? 有没有办法让Cordova立即加载WebView并让JS在后台初始化插件时加载并在必要时触发deviceReady I can do Cordova specific things at a later point of time. 我可以在稍后的时间做特定的Cordova。

Related: 有关:

  1. Showing webView in Cordova before API has loaded 在API加载之前在Cordova中显示webView
  2. phonegap plugin onload=false has no effect phonegap插件onload = false无效

I empathize with your goal, but you cannot get milk from a turnip . 我同情你的目标,但你不能从萝卜中获取牛奶。

With the idea of using onload=false , the <feature (...)> has been deprecated. 使用onload=false的想法, <feature (...)>已被弃用。 Follow the link at the bottom, and read #12. 按照底部的链接,阅读#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. 在另一个问题上,很明显,提问的人不知道这是不可能的。

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. 所有Cordova / Phonegap平台的主UI查看器都是一个名为WebView的库(在Android中,在其他平台上类似, 请参阅 )所有这些库都有一个共同点,即不加载,Javascript或其他工具可以实现它一个完整的webbrowser。 As a result, Javascript must be enable (by Cordova) and loaded (by the OS). 因此,Javascript必须启用(通过Cordova)并加载(由OS)。 This does not happen until all the other portions of the HTML document are recognize (but perhaps not loaded); 直到HTML文档的所有其他部分都被识别(但可能没有加载)才会发生这种情况; this includes CSS, fonts, images and icons (if needed). 这包括CSS,字体,图像和图标(如果需要)。

However, on the later items, CSS for instance, time can be made up - if the CSS is optimized. 但是,在后面的项目中,例如CSS,时间可以弥补 - 如果CSS已经优化。 Many times developers do not do this optimization, because of a need to deliver a milestone (and they often never return to fix it). 很多时候开发人员不进行这种优化,因为需要提供一个里程碑(而且他们通常永远不会返回来修复它)。

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. 加载后的插件必须进行* some *初始化,但需要多长时间取决于插件。 For instance, the geolocation (GPS) plugin can take as long as 10 seconds before a usable reading is available. 例如,地理定位(GPS)插件可能需要长达10秒才能获得可用的读数。

  • 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. 所以这将是徒劳的努力。

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,Android和Apple的iOS文档的阅读。

This document may prove useful while you are developing 在开发过程中,本文档可能非常有用
Top Mistakes by Developers new to Cordova/Phonegap Cordova / Phonegap新手的开发人员面临的重大错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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