A few weeks ago my brother approached me and asked me if I could help him setup a mobile site for his company. He’s a professional photographer and beyond his landing page, the site is entirely flash and therefore not mobile friendly.
Working for an internet technology firm has it’s advantages. I was able to quickly ask around and find out exactly what is needed, and it’s actually rather simple.
Though it seems backwards, we’ll start from the end and work back. If we’re going to send users to a mobile site, we have to have a mobile site in place. With a simple text editor and some relative paths to logos (optimized for mobile phone screens), one can build a simple mobile site in a matter of minutes. By “simple”, I just mean that the site isn’t going to have a whole lot of functionality. It will have a landing page, contact info, hours, location/map, and for his business, perhaps a few thumbnails to showcase work. Putting all this together takes about 20 minutes.
Now that we have the “mobile site” built, we need a way to intercepting traffic. The easiest way is a simple “View Mobile Edition” link on his landing page, so that if a user arrives by way of a mobile device, he or she simple clicks the link to see the phone friendly version. To add another level of sophistication–and professionalism–one really needs to employ a “sniffer.”
Defining a list of all of these user agent strings can take awhile, but luckily, you can download some ready made js files that have all the main strings packaged nicely for you–including strings for iPhones, Blackberries, Droids, iPads, Windows based devices, and other smart- and mediocre- phones. Also, Wikipedia has a nice, up-to-date list to make life easier for you.
So, once you have built your mobile site and defined which mobile devices you wish to sniff for, all that’s left to do is call the js file in the
section of your website. This may be in your index.html file or in an include such as header.php if you’re using a dynamically driven framework like WordPress. Either way, the include would look something like:
So, there you have it. You now know how to automatically direct mobile users to a mobile-optimized site. If you have any thoughts on the matter, an easier implementation, or resources that might be helpful, please share them!
Update: Note that user agents are case sensitive. For example, “Blackberry” is not the same as “BlackBerry” (and the latter is correct.)