Mastering Grails: Grails and the Mobile Web (Scott Davis)
Grails, Scott Davis June 17th, 2008
Scott Davis continues his Mastering Grails series with a new chapter: Grails and the Mobile Web. He writes at the introductory section:
These days, thankfully, it’s rare to see a Web site include the disclaimer "Best viewed using [Browser X]." Modern Ajax libraries such as Prototype, Dojo, and YUI do a reasonable job of abstracting away the remaining differences among Firefox, Internet Explorer, and Safari. But people visiting your Web site from a Nokia, Motorola, or Apple cell phone might not enjoy the same degree of browser independence. Even the latest mobile browsers that claim "full HTML support" can benefit from a few simple tweaks to the Web content. This article shows you how to optimize your Grails applications for mobile browsers.
If you’re wondering why you should even bother with making your Web site mobile-friendly, the numbers in the Mobile Web use on the rise sidebar might convince you. As impressive as the global statistics are, my interest in a mobile-friendly Web is more personal. I bought an iPhone when they first came out in summer 2007. Since then, I have been actively seeking out Web sites that are usable on the device. Sure, I can visit any Web site (as long as it doesn’t rely on Flash or Java™ applets, which the iPhone doesn’t support). The problem is that content optimized for 800×600 resolution (or higher) doesn’t look quite as nice on a 3.5-inch screen.
The Web sites I use regularly from my phone are the ones that meet me halfway with a UI that caters to the device’s unique constraints. Substituting an m for the traditional www in popular Web sites’ URLs is a good place to start. The pages at http://m.cnn.com, http://m.yahoo.com, and http://m.google.com all look good on my phone. Some Web sites, such as http://www.twitter.com, morph to the appropriate output magically: when I’m on a computer, I get all of the features; when I visit from my phone, the content is trimmed down and fits my screen like a glove. Same URL, optimized UI. I’ll show how your site can do these things too.
He then proceeds to explain some of the formats mobile devices will accept to display web content and how to produce content in said formats from your Grails enabled application. He even targets eye-candy gadgets as the iPhone. He finalizes the article by giving some advice to properly handle mobile clients without compromising your regular browser clients, mainly by
- Creating a separate, dedicated Web site for mobile content
- Sniffing the user agent
- Sending back what the browser accepts
Probably some smart template management will also help to avoid file duplication, but that depends on your application needs.
As he points out at the beginning, mobile devices are everywhere, the number of connected devices increases as days go by. Given this accelerated rate and that there are more mobile/emebedded devices than computers out there, this article is a wake up call for those that want to stay in touch with customers in all ways possible, and what better way to do it by being productive with Grails at the same time.
Tags: Grails, Scott Davis
About
Leave a Comment