Widgets, Mobile Web 2.0 and Javascript
With all the buzz about Mobile Web 2.0 and widgets I have had some thoughts that people should be careful when using AJAX and Javascript.
AJAX works by using XMLHttpRequest to exchange data asynchronously with the web server. This is all well and good. The idea is that the Javascript application exchanges small amounts of data with the server (often in the background) so that the web page does not have to be reloaded every time the user does something. This is where things gets a bit tricky.
It’s often the case that background fetching is for data that is never eventually used. Similarly, if the Javascript is fetched from the Internet it’s likely that much more Javascript source code is downloaded than is actually run. Both of these…
- Consume battery
- Consume memory (already heavily consumed due to the Javascript runtime)
- Potentially involve data that is billed for but not used
- Slow down the UI due to everything else going on
These problems become even more pronounced when the program is running all the time in an idle screen.
While it’s not Javascript, an extreme example of this can be seen in Yahoo’s mobile application. While you are entering data it tries to be clever and downloads extra stuff you will probably never use. This slows down the UI and makes it unusable.
Furthermore, as with any mobile application, poorly written end-user code can poll or enter a tight loop consuming excessive battery power and making the phone appear unresponsive.
One of the unwritten rules of mobile development of all kinds is that you should avoid polling on a status. Code polling is running in a tight loop that causes 100% of the CPU time to be used that, in turn, consumes and drains the battery and can cause the user interface to become sluggish. Instead you should use programming (and OS) mechanisms to cause code to be run only when a state changes.
I am not saying Javascript shouldn’t be used. It’s just that the AJAX model is less ideal than some might hope and it might cause some problems when end-users start creating widgets.
Update: It seems that the Apple iPhone is also suffering problems that are probably due to the way the software has been written…
"Apple software functions built into the phone are sucking juice out of the batteries to the extent that talk time is significantly compromised."