A few things learned from PhoneGap
I’ve spent today coding an app using PhoneGap. It allows people to code a would be webapp and then deploy it as an app on the app market. It also gives the “webapp” super powers and enables it to access things like the accelerometer or the user’s contacts.
The hardest part at first is dealing with errors. I wasn’t aware that in debug mode the android webview sent error messages through LogCat, I thought there were no error messages. As a result I wrote a debug function to deal with that problem but it still took a while to make something simple.
Another problem is the size of Javascript libraries. jQuery, as small as it is, is too big for my phone. The app lagged a lot when I included jQuery so I had to remove it. Instead I wrote a few functions, “byId”, “hide”, and “show”, in place of what I was using jQuery for. Apparently there is XUI, a very small mobile Javascript library, which I may try when I write my next app.
At nearly 3,000 lines of code, phonegap.js isn’t very small either (90k). I spent about 30 minutes looking over this file and I found some interesting soon to be realesed APIs. File access and database access where a few things that I noticed were being worked on.
There are a few things that could be done to make PhoneGap apps faster. Firstly, I was quite puzzled as to why the phonegap.js file was so big. The file could be minified but I’m not sure how much that would help with the speed of apps. I think the main problem is that it spends about the first 700 lines of coding setting up this (crazy?) callback server / pubsub channel thing. I’m not at all sure why that is necessary and I think everything would be simpler without that (more specifically instead of using this big callback system PhoneGap could just add the accelerometer and other objects as Javascript interfaces through the WebView).
That being said, I think PhoneGap does what it does for cross-platform stuff (haven’t looked at the other .js files for the other systems) but I’d like to remove it completely from my Android apps to make them more responsive. Instead of PhoneGap I would add Javascript interfaces and that would lessen the amount of Javascript the phone needs to run. I would still use the same API that way porting to iOS (which I intend on doing) would be easier.
note: My current phone is an HTC Hero (CM6) and my app seems quite slow. Running on an Evo or Droid might make it very responsive in which case I would say PhoneGap works very well.