BlackBerry and JavaScript: Oil and Water?

Mobile Development Comments (0)

With the abundance of smartphones that come with highly capable, webkit-based mobile browsers, developing and deploying functional and engaging web applications can be made much easier by leveraging existing, proven frameworks such as jQuery, prototype and MooTools. In fact, such is the quality of these mobile browsers that a web application previously developed for “traditional” browsers (i.e. non-mobile) will work as-is, with perhaps some UI-focused changes to cater to the different user input methods and reduced screen real estate.

The elephant(s) in the room, though, (in terms of market share) when it comes to rich, JavaScript-based web applications, are BlackBerry devices. These still immensely popular mobile devices are notoriously deficient when it comes to executing anything but simple JavaScript code. This seemingly sounds a near death knell to hopes of having BlackBerry users, and therefore a significant portion of the mobile audience, being able to engage your carefully crafted web app. All is not lost, however. With some judicious scaling back and rearchitecting of your web application, you can still provide a useful, functional experience to the BlackBerry audience, while still maintaining the high quality experience for the remainder of the browser audience.

First on the agenda will be agent detection, to determine if your web app is being requested by a BlackBerry device. Searching for the string ‘BlackBerry’ in the user agent string will hit the vast majority of use cases, though for complete accuracy there are a number of libraries available that both greatly simplify the detection process and ensure 100% (or as close as is reasonably possible) accuracy. Two such (PHP based) libraries are WURFL and DeviceAtlas, both of which are easy to install and utilize. Note that while client side detection is possible, the more reliable browser detection libraries come bundled with the main frameworks (such as jQuery) and our experience is that the mere inclusion of these frameworks on a page will cause JavaScript execution to stop.

Once you have determined that the requesting device is a BlackBerry, you will then need to determine what to do with this information. The cleanest solution we have found is to redirect the user to a page that is specifically tailored to BlackBerry devices. This will remove the need to clutter your main web application (the one targeted to the more fully featured web browsers) with an overabundance of conditional statements in a misguided attempt to create a one size fits all solution. This can not only result in unreadable code but can lead to the temptation to scale back the functionality of the primary web app intended for your larger audience.

Assuming you have chosen the path of building a separate, BlackBerry-specific version of your web app, now comes the work of actually building out the page(s). Though this may seem like an onerous task (build more functionality from scratch?..ugh!), it is one, in our experience, that goes smoothly. Most of your server side business logic will remain the same as you should strive to keep the essential interactions of your app the same in relation to your primary web app, instead focusing on simplifying the JavaScript-based UI aspects of your application: for instance, changing an animated sub menu roll down when clicking a main menu item to a simple show/hide interaction. Not as visually appealing, but one that provides the same functionality to the end user.

Once you have reviewed your application and determined what interactions will be restructured, it’s time to get down to work on coding those new (or restructured) interactions. While it may seem like taking a huge step backwards, you should first ditch all code based on a framework (i.e. jQuery) and instead aim to write your code directly utilizing the DOM level 2 API (i.e. getElementById(), appendChild(), etc.), as prescribed by the BlackBerry reference documentation. Although newer BlackBerry devices will support more advanced API calls, targeting the level 2 API will ensure your application will perform reliably across the widest possible range of devices. One time-saving strategy in this regard would be to develop in house a DOM level 2 only library of code that implements commonly performed tasks: for instance, image rollovers, dynamically refreshing the content of a specific page element, etc.

While having to go through procedures like this in order to ensure widespread acceptance of your web app may not be the most attractive proposition, things in the BlackBerry arena do seem to be looking up. The new generation of BlackBerry devices coming out, specifically the Torch, come bundled with a Webkit-based browser, which obviously reopens the door to all of our favorite JavaScript frameworks. While this doesn’t address the still huge population of older, non-Webkit BlackBerry devices, there is good news on that front too, in that frameworks are on the horizon that specifically target the mobile space. Chief among those are the soon-to-be released jQuery mobile, and the XUI framework which is considering adding BlackBerry support in the future. While frameworks such as these might not necessarily negate the need for BlackBerry specific versions of your web apps, they will certainly speed and simplify the development of them.

When all is said and done, there may still be some “smart” in the BlackBerry smartphones.

Follow Float
The following two tabs change content below.

Mark Tovey

Mark is a Mobile Developer at Float with a B.S. in Applied Science (Information Science). Mark has a varied background in the I.T. industry, having worked as both a mainframe programmer/analyst and web developer over the course of his career, in areas as diverse as homeland security, education, insurance, e-commerce, and e-learning. This breadth of experience has given him a deep understanding of all of the phases of the software development life cycle. In the recent past, Mark has developed many content managed websites using open source software, including the Oyez Project, as well as developing interactives for clients such as The Adler Planetarium and Shure Inc. Mark is also an instructor at Bradley University, teaching an introductory course to the Javascript and Actionscript scripting languages.

» Mobile Development » BlackBerry and JavaScript: Oil and...
On August 20, 2010
By
, ,

Leave a Reply

Your email address will not be published. Required fields are marked *

« »