简体   繁体   中英

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).

What I have tried so far:

  • 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 )

  • 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:

  • 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.

  • 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.

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 deviceReady whenever it has to? I can do Cordova specific things at a later point of time.

Related:

  1. Showing webView in Cordova before API has loaded
  2. phonegap plugin onload=false has no effect

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. 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.

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).

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).

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.

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.

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

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