Creating Mobile Websites
This article was published in the Mobile Developer’s Guide To The Galaxy #9 in October 2011.
Why create a mobile website instead of an application? Using the web has a number of advantages, websites can be browsed on most devices, the technology is flexible, and it is easy to update sites so all users get the latest version. You only need to modify a single codebase if you want to add or change content or even features, rather than updating each application.
Context Is King
When you create a website for desktop browsers you typically design and develop for a context in which a user has a large display, enough time, power and also a fast persistent internet connection. None of these are guaranteed when using the internet on mobile devices.
Although most new devices have much larger screens than devices a few years before, they are mostly still small compared to desktop devices. Beyond that users often access a mobile website when they are on the go and they may be focusing on other things in addition to the web site they are using because they have to look at the traffic for example.
Other problems to consider are the effects of a weak signal and a slow mobile internet connection. Since the average internet user is impatient, you can easily lose a user who has to wait too long for pages to load – they may obtain the information elsewhere. Therefore you should try to keep content such as external scripts and images as small as practical.
You should consider these factors when you are about to design a website for mobile devices. Focus your mobile web strategy on what content a user is probably looking for when they visit your website. They are unlikely to be interested in your awesome company intro page animation made in Flash. Beyond you should also think about the contexts in which your mobile site will be used before you begin to design a mobile website.
It could be in a train with a weak signal, in a village with poor connection speed, outside in a sunny environment on a top-notch smartphone with touchscreen display as well as on an older feature phone with an even older browser and keypad operation. You cannot influence the context a user is in but you can design your site to be useable under all these circumstances.
After thinking about content and context it is equally important to consider usability. It is not only a matter of what content is interesting for a user and the contexts in it will be consumed but also a matter of how your target audience will use your site. Navigating your site is less fun when doing it using the device’s keyboard instead of just using your finger on a large screen but it can be easier if the links within your page are so damn small that it is almost impossible to hit them without causing unwanted behavior (like tapping other links as you actually wanted to). There are some basic hints to make sure your content is adapted in the best possible and usable way for mobile users:
- Make it “mobile” not only “small”: Create a concept that utilizes the possibilities of the technology. You won’t satisfy many people by simply offering a smaller version of your classic website. Mobilize, don’t miniaturize!
- Keep all paths open: Leave it up to the user to access either the mobile or desktop version of your website.
- Keep it simple: Avoid complex navigation structures, users will not dig that deep anyway while they are on the go.
- Avoid text input wherever possible: Text input on mobiles sucks. If you really need the users to enter text, use wide input boxes so that they see what they are typing. Buttons to clear an input field on click/touch are also helpful very often.
- Adapt the media: Adapt all pictures, videos and alike to be displayed properly on the handset (check the corresponding chapter in this guide: “Implementing Rich Media” for more information). Try to avoid formats such as .doc and pdf if possible.
- The user is a creature of habit: respect that: Adapt usage patterns from classic websites such as linking logos to the homepage or offering corrections to mistyped search requests.
- Think of stubby fingers: When optimizing your content for touch screen phones do not use clickable areas smaller than ~50x50px.
- Use sharp contrasts: Fonts and background colors that guarantee legibility in any surrounding, including bright sunlight.
- Reflect continuously: Ask yourself if you would use the implemented features yourself. Ask your friends and colleagues as well before realizing your ideas.
- Do not require the user to think. Try to implement intuitive navigation, do not force users to make decisions more often than necessary.
Technical Limits of Web Technologies
When it comes to the decision whether to create an app or a mobile website for a specific project many mobile developers tend to say “app” first because you seem to have more possibilities and better performance. This answer is seldom wrong but it is only half the truth. Let’s have a detailed view on the advantages and disadvantages of mobile websites or web apps compared with native mobile apps.
If you are coming from the “desktop world” and you have never created a website for mobile devices before (or if the last time you did is already a long time ago) you will be surprised about the capabilities of modern mobile phone’s web browsers. Assuming that you intend to optimize your mobile website mainly for modern platforms you would also create apps for (iOS, Android, BlackBerry OS, WebOS, bada, Windows Phone) we will primarily focus on modern browsers running on the mentioned platforms in this chapter.
And that’s not all: almost all recent mobile browsers support a lot of the current CSS3 standard and so you can create nice and shiny things like transitions, custom web fonts, drop shadows or rounded corners with only little effort which makes it very easy to let your web applications look and feel like native apps.
|Feature||Mobile Website||Native App|
|Detect online status||Yes||Yes|
|Offline data storage||Yes (very limited)||Yes|
|Access GPS sensor/geolocation||Yes||Yes|
|Access camera||Not yet (planned)||Yes|
|Access address book||Not yet (planned)||Yes|
|Notifications (i.e. vibration, push, messages)||Not yet (planned)||Yes|
|Check battery status||Not yet (planned)||Yes|
|Different touch keyboard layouts on input fields||Yes (incomplete)||Yes|
|Appstore approval needed?||No||Yes|
“In mobile, fragmentation is forever”. Unfortunately it is not always as easy to create a cross-device cross-platform crossbrowser cross-markup “cross-blahblah” mobile website as you might think. Dealing with many different devices also results in an annoying fragmentation jungle. Some devices use their own implementation of device APIs (i.e. Geolocation on Blackberry OS 4.6) or even have absolutely no support for certain features (i.e. filesystem access on iOS).
This means you have to write workarounds of your code for different platforms and even for the same browser running on different platform versions. But the web wouldn’t be the web if there wasn’t already a solution for almost all of these problems. And so there are sites, libraries and services like caniuse.com, Modernizr or fitml.com where you can build quick and clean workarounds to handle fragmentation issues with only a minimum of effort. You still only need to write most parts of your web app once.
Server-Side vs. Client-Side Adaption
Basically there are two different approaches to professional mobile web development if you aim to deliver a great user experience. Either way you will have to determine which (type of) device is sending a request to your website and then you need to “guess” (server-side) or test (client-side) what features are supported by the according device.
Server-Side Detection and User Agent Sniffing
The first possible way is to do so using the so called “user agent sniffing” on the server-side and then let your server create and deliver an optimized version of your site to the client. Serverside detection is usually based on large databases containing the user agents of thousands of devices and their capabilities. The most common use of server side adaption is image scaling on the server to save some bytes when delivering a big image to a mobile device. In most cases it is not necessary to deliver a 800×600 JPG with a file size of 120K to a device whose display resolution is only 320×480. So you typically resize the image to the display size of the mobile device and then serve a much smaller version to the client.
Service-side detection can be a good choice for other reasons. You can also decide which markup to deliver based on the user agent of the accessing device. If you have a visitor with an iPhone or an Android phone you can serve a nice HTML5 document while users with old Nokia devices will receive an old fashioned XHTML 1.1 document.
The advantage of server-side adaption is that you optimize all the content to serve only what a client probably really needs. And “probably” is also the problem here. New devices are released so often it is hard to keep a device database entirely upto- date. There are some commercial providers for device databases (WURFL, DeviceAtlas, fitml.com for example) if you want to realize mobile web projects with server-side user agent detection I strongly recommend you consider one of these as they have full time employees actively maintaining their databases and do a lot of work that would be impractical for you to do yourself.
Pitfall here: user agents can be “wrong”, manipulated or unknown. You should therefore always provide a fallback in case your user agent detection fails. Such a fallback could be a document in a format (i.e. HTML4) that almost every mobile browser released in the past 5 years can understand.
Client-Side Adaption and Feature Detection
if(navigator.geolocation) to check if a device supports acquiring of the user’s current position.
Feature detection also means that you will have to deliver the complete document with all possible features of the website in it and then gracefully degrade it by removing features which are not supported on the device. That means you are sending a lot of content to all devices regardless of whether a certain feature is supported on a device or not.
One big advantage compared to server-side adaption: when a feature test passes you can (under normal conditions) be sure that your desired feature or behavior will work as expected even if a user agent was modified and therefore was not recognized properly by a device capability database.
if (Modernizr.draganddrop) else
Another part that belongs to the client-side is the adaption of layout. On modern mobile browsers you can use media queries which let you apply CSS rules only if a client or browser matches certain conditions. You can easily show a two column layout when a device exceeds a display width of 800px (on tablets for example) and fall back to a linear one column layout when a device’s display has a resolution of less than 800px.
Why not just use the best of both worlds?
A commercial platform working according to this principle is fitml.com where you describe your content in an abstract XML markup called FITML, the platform then converts your markup to the best suitable output format and optimizes both on serverside and on client-side.
How does it work exactly? Write your complete application in HTML5 just as you were about to publish it to the web. Then you use one of the frameworks to compile your web app as native app. The framework creates some sort of “wrapper app” which embeds your web app in a “web view” and it can then be installed as regular application on several different platforms. The big plus of doing it this way is that you only have one web app as the base and thus you can reduce your costs for development and maintaining but the result is still a “real” native app.
Small downer: although frameworks let you use features in your web app which you usually cannot use in a browser hybrid apps are not a complete substitute for native apps. They offer some nice advanced functions like vibration, access to camera or address book but in its core it still is a web app. That means you will have to create your own user interface which might be slower and you also cannot use really everything as you can when creating an app using the native SDK.
The gap between native apps and web apps is rapidly decreasing. Browser vendors did a lot of good work in the past few years and implemented many features which were only available in native apps. There are different approaches to create great mobile websites which can look and even feel a lot like a native app and new devices will be released that have even better support for HTML5 and its device specific enhancements.
Creating mobile websites or mobile web apps makes your content accessible over the web on almost every platform with only little work compared to native development for several platforms. It can thus save you a lot of costs for development and maintenance. Due to the existence of hybrid app frameworks you can even publish your apps in app stores.
If you have never developed a mobile website or web app before or if you were not convinced because of the poor browsers in the early days of the mobile web you should give it another try. Consistent support of the many different features is still far from perfect but it has been improved by at least 1000% since the rise and success of Android and iOS.
When you became curious and want to create a mobile website always have one thing in mind: make your mobile website mobile, not just smaller!