Cordova

Android development is fairly enjoyable. Windows phone development is rather nice. iOS development is… well, it’s iOS development.

Doing all of these, one after another, to produce pretty much the same app with the same functionality whilst also under time pressure is not enjoyable at all.

There are a slew of products out there claiming to provide a “write once, run anywhere” solution to the problem of cross-platform on development. Given the history of similar claims on the desktop over the years, your faith in such solutions may vary.

Looking through the available options, I’ve chosen Cordova (also known as PhoneGap) as my technology of choice and so far, after releasing two apps on Android and iOS, I’m happy with it.

Here follows some unordered thoughts summing up the good points of the Cordova platform:

  • Cordova is very transparent. The whole toolchain is open sourced, and pretty easy to pick through if you want to see how it works. Some other solutions are complete black boxes, and some go as far as saying “you send us your source code, we’ll do some magic on our servers and send you back a binary”. Scary. Downright scary.
  • The building blocks of your application are HTML and JavaScript. Familiar territory for any web developer.
  • Cordova gives easy access to many device features via plugins, and it’s fairly straightforward (though not completely trivial) to create your own plugins to fill in the gaps.

There are a few downsides. Performance is definitely not up to par with native applicaitions (though, with a little care, it’s not nearly as bad as some people will make out). Also, you do have to deal with the browser quirks that each mobile platform has, as Cordova does use HTML/JS hosted in a browser widget as the foundation of your app.

Finally, here’s a few pointers and gotchas for any about-to-be Cordova developers:

  • Think carefully about the performance of the UI. Don’t keep the user waiting while performing heavy operations in JavaScript. Use the same techniques you would use to keep a web page responsive.
  • Don’t try to mimic the UI of Android, iOS, etc. You’ll burn a ton of time. If having an app that looks native is a deep concern, just develop native. (Personally, I think developers are prone to placing too much value on slavishly following the UI guidelines.
  • Test frequently on every platform you plan to deploy to. If you need to use code specific to one platform to make things work right, just do it. That’s exactly what the merges folder does.
  • Speaking of the folders, don’t be shy about sticking scripts into the hooks folder to help your build along. Seeing as node.js is a prerequisite for using Cordova, you can be sure that every developer on your project hasa nice cross-platform scripting environment available.
  • Sorry, but you won’t be able to bring all of your favourite JavaScript frameworks along for the ride. Some of them just hurt performance too much.

That last point is very important. Prefer tight, tidy, vanilla JS over using a ton of frameworks. I’m convinced that the main reason PhoneGap / Cordova have gained a reputation for being slow is that the first reaction of many web developers is to think “I like jQuery, I’m on mobile. Let’s use jQuery Mobile!”. Don’t do that.

Happy platform-hopping!

comments powered by Disqus