Why and When Cordova is better then React Native ?

Alexandr Zavalii
codeburst
Published in
4 min readJan 13, 2018

--

(This is my first ever post on medium so please don’t be very cruel.)

I have three years’ of experience as a JavaScript app developer and I am working both with React-Native and Cordova wrapper. And I once again concluded that there is no such thing as ‘the perfect tool’, but there are several tools, each of which would be perfectly suitable for a given task.

Summary

React-Native is definitely catching a lot of hype today, nevertheless I won’t talk about the outperformance of React Native and I won’t compare the number of GitHub stars. I will talk about scenarios and requirements of the project when Cordova wrapper is more reasonable to use than React-native in my opinion.

When you should consider using Cordova ?

  1. Your project is both web and mobile application.

With Cordova Wrapper you can build a hybrid application reusing the website codebase. You can have both web and mobile application from the same codebase. For the mobile application build you only have to load cordova.js script in your index.html file which is extremely easy using webpack plugin.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body><% if (htmlWebpackPlugin.options.isCordovaApp){ %>
<script src="cordova.js"></script>
<% } %>
</body>
</html>

Inside the codebase, we can check weather its a cordova app(mobile app) by checking window.cordova object and calling native functions.

if(window.cordova){
cordova.screen.lockOrientation('landscape');
}

Another approach which is pretty awesome is to have one single web application, which will be accessed both by web-browsers and mobile applications, and injecting the cordova remotely in case of mobile application.
With the help of cordova-plugin-remote-injection you inject cordova inside the index.html file remotely.

React Native approach “learn once, write anywhere” is quite controversial. If you stick with React for your web app, it won’t make it any easier for you to develop a mobile application. You cannot simply take your existing React codebase and convert it into a mobile app adding just a few lines of code, which is much more realistic to do by using Cordova wrapper.

Why perform the same task twice, or even three times, isn’t it a bad practice?

2. You want to use any JavaScript library you like in your project

If you know how to build web apps, you’ll quickly feel at home building mobile apps using Cordova wrapper. And if you have an index.html file in your application you are ready to build your mobile app. The core criterion for the app is the requirement that it should be a Single Page Application (SPA).

Examples of SPA libraries you can use in your Cordova applications are:
AngularJS
EmberJS
Backbone
Kendo UI
Monaca
ReactJS
Sencha Touch
jQuery Mobile

https://cordova.apache.org/docs/en/latest/guide/next/index.html

If you stick to React Native, you restrict yourself to React.

3. Your intention is to deploy an application to as many platforms as possible ( iOS, Android, Windows Phone, Blackberry)

Cordova wins when it comes to platform support. You can install and run anything related to Cordova on any device, which has an interface or web browser capability. Using Cordova, we create TV apps for seat-back screens that provide passengers with a set menu of the in-flight entertainment system.

Nevertheless, React Native is targeting Android and iOS platforms.

Cordova Platform Support :
https://cordova.apache.org/docs/en/latest/guide/support/index.html

4. If you need a native-like performance of your app why use React-Native, and if you don’t, why use it anyway?

If you need a native-like performance of your app, a native approach makes the most sense. You have no alternative but to write it in Swift/Kotlin. Neither Cordova nor React Native is a native application and cannot compete with real native apps. Since JavaScript is single threaded, we may have trouble running our React Native or Cordova application. React Native utilizes multiple threads and UI is manipulated exclusively on the main thread. The same is with Cordova: JavaScript in the WebView does not run on the UI thread, it also has other threads to execute the html component and carry out CSS transitions.
Better performance in React Native is due to the removing of WebView middle layer.
Not sure if it’s worth to have slightly faster app, but it also depends on your project, team and requirements.

5. You do not take into account technologically obsolete and vintage devices.

Moore’s law don’t let us down. Mobile devices today have blazing fast processors, faster than my PC two years ago. Anything faster than iPhone 5 is great for hybrid apps. If there are not too many things going on in our application, webview is good enough.

Conclusion:

Finally, What’s Best ? React Native or Cordova?
React Native and Cordova have different purposes and each serves different needs. Therefore, it’s hard to say which type of app is better. I believe that the choice depends on a bunch of factors. They both do different things, and both do them well.
I hope the provided points will make you think before choosing the right tool.

Please check the amazing conference “AGENTCONF 2018” in Austria, Dornbirn.

Learn, Talk and Ski

You will meet world class engineers from Google, Facebook, Appollo GraphQL , Zeit and many more.Getting inspiration from these experts is the #1 driver why people from America, Europe and Asia make their way to AgentConf every year!

https://www.agent.sh

--

--

Software Engineer in Workday. Passionate about Javascript and front end trends