Wkwebview Performance improvement for Cordova iOS platform

Source: Internet
Author: User

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.

    • Talk about the homely

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.

    • What does that mean?

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

    • Installation steps

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.