I’ve been developing an iPhone app for a client, and it’s been a real eye opener. Rather than dealing with the intricacies of Objective C, I’ve done it using PhoneGap. (Back end in ColdFusion, of course.) I’ve really enjoyed the way PhoneGap lets me leverage my existing skills. However, it hasn’t been without its challenges, and at times, it has forced me to rethink some of my development methods. Luis Medel just released Bentled (http://www.blinkingbits.com), a fun block style game, and shared his thoughts with the PhoneGap mailing list. His post follows.
OK, as promised, here are the lessons I learned during the development of Bentled (http://itunes.apple.com/us/app/bentled/id413851869?mt=8)
I started to write a full log of my development experience but it’s too long and maybe is best suited for a blog post series. I don’t want to bore you, so I’ll put here the main points instead of the full text. While are not exclusive to Phonegap, I hope you’ll find them useful.
- I started to write Bentled for Android and iOS but ended switching to iOS only. Why? Android is a great platform, sure, but lacks the uniformity iOS has. I don’t want to start a flame here, but I have to say this: working with all those different devices (processor speed, ram amount, screen size, etc.) is a PITA. Also, there are a few annoying bugs in webkit on 2.x that can drive you nuts (https://groups.google.com/group/phonegap/browse_thread/thread/5788393afdd00337?hl=es&pli=1)
- Test as soon as you can on all your target platforms to prevent surprises and, more important, test as soon as you can on the real thing to prevent performance issues.
- If you want to write a game and you think the canvas element is a good idea, think again. Nowadays canvas rocks in the desktop. You can use it to create fancy graphics and so in a mobile device, but nothing highly interactive at the moment of writing this.
- Your app needs to be fast but also *look fast*. I recomend writing a mini javascript framework optimized to your coding style, as I did. If you don’t want to spend time, you can use zepto.js but forget about jQuery and other “desktop oriented” frameworks. They are full of compatibility crap.
- Every overlapping DOM element (even transparent ones!) will add a tiny overload to your app. Check your coordinates and remove unused elements.
- For the sake of $DEITY, learn and use webkit transitions! You’ll be amazed how smooth your animations will be.
- If database access is a big concern (such as in game) don’t waste your time and use Lawnchair.
- In the emulator, database access is very fast. On a real device there is a tiny delay in the write. If you want to go to another page after saving some data to DB, set document.location after a short timeout to give the device time to write.
- This is a personal preference and related with the last point: Try to write your app inside only one html file. I wrote my game using several files and page transitions are a bit slow (I’m working on correcting this right now)
- For audio, avoid MP3 and WAV and use native formats as CAFF and AIFC (see: http://www.sparrow-framework.org/2010/06/sound-on-ios-best-practices/)
- Practically cliche, but always true: Being an experienced programmer it’s a shame to admit that I fell in the “optimization nightmare” just at the beggining of the project. Please, do not overoptimize your javascript. Mobile javascript engines are fast enough. The main bottleneck is in the document manipulation and/or canvas blitting. You can use Google Closure compiler. It’s a great piece of software.
- For iOS, develop with a 320×480 screen in mind but include in your bundle resources for both normal and retina screens. Switch to hires images using CSS, javascript or the method you want and you are done. Don’t try to save space using only hires images as the screen will flick a lot.
- iPhone 3G can be slow even for basic DOM manipulations
- Oh, and last, not a tip but a request instead. If you installed Bentled, please, rate it on the App Store. It’s stucked deep in the rank



Thank you for this! We’re optimizing our PhoneGap build of Skej now. (skejnow.com)
Great tips!