Using Cordova as a cross-platform development has long been a headache for Android performance and page rendering, because there are still a few people using the average mobile phone, the version between 4.2-4.4, and even unable to support the HTML5 flex layout, So we had to use crosswalk to enhance our webview, but it did bring us almost 20M of the installation package. Anyway, Cordova in IPhone6 is very fast, but for iOS there will still be a majority of people using the IPhone4 series or IPhone5 series, on these phones do not match iPhone6 ratio, now wkwebview can make it a significant increase.
The ionic framework has grown in sophistication, making it easy for us to achieve a similar experience to the original, but the speed of the app is a necessary condition, and we find that most NB apps share a common feature, which is fluency. In fact, the principle of bare Cordova is to use the local webview of each platform to run a Web page deployed on this machine, and to use JS to invoke the underlying related interfaces.
iOS Default Web browser is Safari, currently iOS offers two different sets of WebView technology, one is a little old "UIWebView", one is Young "Wkwebview",
Wkwebview is significantly faster than UIWebView in terms of performance, which we call "giant fast", and now Apple is updating it in the newly released iOS version because
Safari app needs Wkwebview, previously for various reasons is ionic can't seamlessly fused wkwebview, just this morning I suddenly found ionic has solved this problem, we remember this person called "Manu", Let me use the Chinese way to tell you the good news, the official is announced on August 18, 2016 news.
You can use Wkwebview to make your Cordova app faster and smoother in iOS,
Wkwebview solves many of the problems that Cordova engineering faces, such as XHR requests and cors, storage problems, and some performance problems with rendering the DOM, which upgrades the native-to-network interface, which means that this only wants to xhr the requested file: The protocol is intercepted and redirected. However, the normal XHR request will be passed.
Not only that, the memory consumed by the Wkwebview operation has been significantly reduced, making it faster to start the application (previously I experimented with "Panda finance" app,iphone6,6s boot less than a second, iphone5,5s,5c to 4-5 seconds), Using JIT to compile JavaScript, improve stability and security, and meet the latest web standards, the official experiment is that they use the Wkwebview after the memory from 160MB to 20MB, in terms of stability, the crash rate decreased by 70%.
Now Ionic has released the Wkwebview plugin Cordova-plugin-wkwebview-engine
Address: Https://github.com/driftyco/cordova-plugin-wkwebview-engine
To install the plugin:
add https://github.com/driftyco/cordova-plugin-wkwebview-engine.git --save
During use, you can determine whether it is UIWebView or wkwebview by testing if it supports INDEXDB.
if (window.indexedDB) { console.log("I‘m in WKWebView!");} else { console.log("I‘m in UIWebView");}
Configure the required permissions in CONFIG.
<feature name="CDVWKWebViewEngine"> <param name="ios-package" value="CDVWKWebViewEngine" /></feature><preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
Wkwebview Performance improvement for Cordova iOS platform