Media queries, server-side or client-side sniffers, how do we determine if the user is a mobile or desktop device? This tech talk will discuss which is the right solution(s) and how to implement it taking into consideration the various mobile user's browser capacity, bandwidth restrictions, as well as user choice.
Jenifer Hanen
@msjen
http://blackphoebe.com/msjen
8. My Hunch was Right.
! <script type="text/javascript">
! var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
! document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/
javascript'%3E%3C/script%3E"));
! </script>
! <script type="text/javascript">
! try {
! var pageTracker = _gat._getTracker("UA-8949178-1");
! pageTracker._trackPageview();
! } catch(err) {}</script>
6 months after launch,
57% of users were coming to the
site via a BlackBerry browser, 23%
with an iPhone, & the rest was
desktop browsers.
9. Let’s Talk Bandwidth:
Meet Rita El Khoury
Lebanese
Pharmacist
Mobilist
Blogger
ritaelkhoury.com
iPod
Nokia N8
HTC Desire Z
10. Data is Expensive in Lebanon
“Data plans in Lebanon are divided between prepaid and
postpaid plans. Most people are on prepaid, the only deal
they can get is a fixed 25MB/month for 5$ or 3$, non
renewable before another month.
On postpaid, we get 3 plans:
50MB for 10$,
120MB for 15$,
250MB for 30$.
Every additional MB costs 0.10$.
I am on the 120MB plan and I do just fine, most months
hovering between 100 and 160mb of use. Those are all
EDGE connections by the way, we have been on them for
approximately 2years. 3.5G is promised to be deployed in
the summer.”
- Rita El Khoury, May 2011
11. Not an Ad
“For the mobile web, I exclusively use Opera Mini. Whether on my
iPod, Nokia N8 or Desire Z, Opera Mini is the only browser I will use.
Its data efficiency is the reason I can view all web pages I need access
to on the go without going ridiculously over my cap.” - Rita El Khoury, 2011
13. Three ways to put the Mobile in the Mobile Web:
CSS : The famed and lauded Media Queries
Javascript : Oh Braces, camelCase & Semicolons
Server-Side : Fear Not
14. <!DOCTYPE html>
As always, we need to
start with good, <html>
semantic markup.
XHTML or HTML5 ...
Which should I use? </html>
It depends... or
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN"
"http://www.w3.org/MarkUp/DTD/xhtml-basic11.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en" >
...
Update: It was pointed out to me by Jeremy Keith & Paul Stevens
</html> that this is about DTDs, not XHTML v. HTML, will blog about this.
15. CSS : The famed and lauded Media Queries
http://www.flickr.com/photos/jcroft/112754603/
16. In Ethan Marcotte’s Responsive Web Design article,
he advocates for the use of:
CSS @media types & query
<link rel="stylesheet" type="text/css"
media="screen and (max-device-width: 480px) and (resolution: 163dpi)"
href="shetland.css" />
Flexible layout
@media screen and (max-device-width: 480px) {
.column {
float: none;
}
}
Flexible images
@media screen and (max-width: 400px) {
.figure,
li#f-mycroft {
margin-right: 3.317535545023696682%; /* 21px / 633px */
width: 48.341232227488151658%; /* 306px / 633px */
}
li#f-watson,
li#f-moriarty {
margin-right: 0;
}
}
http://www.alistapart.com/articles/responsive-web-design/
17. Mr. Marcotte is not the only one who is a proponent of
Responsive Web Design and Media Queries...
Stephen Hay will be presenting next on
Meta Layout: A Closer Look at Media Queries
http://www.slideshare.net/slideshow/mobilism2011
For examples & inspiration: http://mediaqueri.es
18. CSS Media Queries Pros and Cons:
Pros:
* Uses CSS, relatively simple for web workers
* If budget does not allow for separate mobile web site, one
can make it apart of current website that accounts for screen
sizes.
Cons:
* Does not take into consideration bandwidth or kind of
connection - mobile data or wifi?
* While there are a few image reduction solutions, they are
not quite there yet.
* Umm.. Cough Cough... Internet Cough Explorer Cough...
* Most importantly for data sippers, all scripts and media
objects are loaded by the mobile browser even if the @media
gives a different layout & images for the small screen.
19. Mobile Sites Are A Must:
Meet CJ!
3rd Culture Kid
CompSci by Degree
Blogger by Love
zomgitscj.com.com
iPad
Nokia(s)
Many Mobiles
20. Why Mobile Sites Are A Must:
“I think a lot of folks assume that everyone out there
has a 3G plan, that's unlimited or has a lot of leeway. In
India's case, that's definitely not true, and as such folks
tend to avoid websites that might be too data
intensive, or use way too much flash. A Mobile-friendly
version is a must here, if you want people to visit your
site.
And unfortunately, at least here in Delhi, Free Wifi can
be hard to find, so heading to a coffee shop to leach off
their Wifi is not an option.” - CJ, May 2011
21. -|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-
s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er
(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|
Javascript : Oh Braces, camelCase & Semicolons
gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi
(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|
Javascript opens up our options for Mobile
go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|
detection, which then allows us to create a
iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|
better experience for the mobile web viewer.
kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|e-|e/|-[a-w])|libw|
lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me
It can be as simple as using Javascript to detect if
(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|
it is a mobile device, not just by user agent
zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|
strings but by features of the mobile web
n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|
browser.
nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|
-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt
With Javascript there are several approaches:
-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|
rim9|ro(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p
24. One Not So Small Problem
Not all mobile browsers are Javascript equal and
some feature phones have little to no Javascript.
Please refer to the Mobile Compatibility tables:
http://quirksmode.org/m/table.html
25. But we can’t count Javascript out...
Many have great hopes that JQuery Mobile will
mature in a way that the web trio of HTML/CSS/JS
will be more than enough for the mobile web,
as well as, other future Javascript solutions
for the mobile browser.
Scott Jehl will be presenting on JQuery Mobile after lunch
26. How do we build for a
complex Mobile Web?
Meet Chandrachoodan
Filmaker / Archaeologist
MA from U. of Bristol
Photographer
Blogger
Chennai Proud Nokia E63
27. “I think that support for Indic scripts would be very important in the future. More and more Tamil/
Hindi/Indian language publications are getting online, and a lot of Tamil blogs already exist. So support for
Indic scripts on the mobile web essential. I realise this is an issue with slightly older phones and that
newer phones come with UTF-8 support.” - Chandru, May 2011 Photo by Jenifer Hanen
28. Server-Side : Fear Not
You have determined that you need a mobile web site or app
that works for many connected mobile devices, including ones
that Javascript may not work with and for users who are
bandwidth sensitive. Time to look to the server.
If the word server-side gives strikes fear in your gut, worry not,
if you are willing to calculate fluid grid percentages to the 8th
decimal point then what is a wee bit of server-side scripting
between friends...
margin-right:
3.317535545023696682%;
width:
48.341232227488151658%;
29. The PHP Script from Detect Mobile Browser
<?php
$useragent=$_SERVER['HTTP_USER_AGENT'];
if(preg_match('/android|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|
lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)/|plucker|pocket|psp|symbian|treo|up.
(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i',$useragent)||preg_match('/1207|6310|6590|3gso|
4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|
attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55/|capi|ccwa|cdm-|cell|
chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er
(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|
t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|/)|ibro|idea|ig01|ikom|
im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|/(k|l|u)|50|54|e
-|e/|-[a-w])|libw|lynx|m1-w|m3ga|m50/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo
(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne
((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|
pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro
(ve|zo)|s55/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl
(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|
tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|
voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(-|2|g)|yas
-|your|zeto|zte-/i',substr($useragent,0,4)))
header('Location: http://detectmobilebrowser.com/mobile');
?>
Looks quite a bit like the Javascript DMB script, the RegEx for mobile browser UA’s
remains the same, but the Javascript is swapped out for PHP at the top & bottom.
http://detectmobilebrowser.com/
30. <?xml version="1.0" encoding="UTF-8"?>
<wurfl>
WURFL
<version>
<ver>www.wurflpro.com - 2011-04-24 12:07:53</ver>
<last_updated>Sun Apr 24 12:09:17 -0500 2011</last_updated>
<official_url>http://wurfl.sourceforge.net/</official_url>
! <maintainers>
! <maintainer name="Luca Passani" email="luca.passani at gmail point
“The WURFL is an XML configuration file which contains com" home_page="http://www.wurfl.com"/>
! </maintainers>
information about capabilities and features of many mobile ! <authors>
devices. ! <author name="Luca Passani" email="luca.passani at gmail point com"
home_page="http://www.wurfl.com"/>
! </authors>
</version>
The main scope of the file is to collect as much <devices>
information as we can about all the existing mobile <device id="generic" user_agent="" fall_back="root">
<group id="product_info">
devices that access WAP pages so that developers will be <capability name="mobile_browser" value=""/>
able to build better applications and better services for <capability name="nokia_feature_pack" value="0"/>
<capability name="device_os" value=""/>
the users. <capability name="nokia_series" value="0"/>
<capability name="has_qwerty_keyboard" value="false"/>
<capability name="pointing_method" value=""/>
This project is open-source and is intended for developers <capability name="mobile_browser_version" value=""/>
<capability name="is_tablet" value="false"/>
working with the WAP and Wireless. All the information <capability name="nokia_edition" value="0"/>
listed here has been collected by many different people <capability name="uaprof" value=""/>
<capability name="can_skip_aligned_link_row" value="false"/>
from many different countries.You are allowed to use <capability name="device_claims_web_support" value="false"/>
<capability name="ununiqueness_handler" value=""/>
WURFL in any of your applications, free or commercial. <capability name="model_name" value=""/>
The only thing required is to make any modification to <capability name="device_os_version" value=""/>
<capability name="uaprof2" value=""/>
this file public, following the original spirit and idea of the <capability name="is_wireless_device" value="true"/>
<capability name="uaprof3" value=""/>
creators of this project. This will help WURFL to grow <capability name="brand_name" value=""/>
better and better every day.” - Luca Passini <capability name="model_extra_info" value=""/>
<capability name="marketing_name" value=""/>
<capability name="can_assign_phone_number" value="true"/>
<capability name="release_date" value="2002_january"/>
<capability name="unique" value="true"/>
http://wurfl.sourceforge.net </group>
<group id="wml_ui">
<capability name="icons_on_menu_items_support" value="false"/>
http://tera-wurfl.com/explore/
<capability name="opwv_wml_extensions_support" value="false"/>
<capability name="built_in_back_button_support" value="false"/>
<capability name="proportional_font" value="false"/>
<capability name="insert_br_element_after_widget_recommended"
value="false"/>
<capability name="wizards_recommended" value="false"/>
<capability name="wml_can_display_images_and_text_on_same_line"
value="false"/>
<capability name="softkey_support" value="false"/>
<capability name="wml_make_phone_call_string" value="wtai://wp/mc;"/>
<capability name="deck_prefetch_support" value="false"/>
<capability name="menu_with_select_element_recommended"
value="false"/>
31. What Challenges do you
face with bandwidth?
Meet Jason
San Francisco
Web Developer
Photographer
iPhone
32. San Francisco, Connection Black Hole
“It depends on where I am. At my old place in the Inner Sunset, very rarely did my
phone drop calls, and I always had great reception. Now in the Castro, and when I'm
downtown, I get dropped calls frequently, and at home I need to be near the
windows at the front of the apartment to make sure I don't lose reception. Even
then, it might not help. If I happen to walk into the kitchen without thinking about
it, I might as well say "good bye" on the way because the call will certainly drop.
At home, when I'm visiting friends, or somewhere with free wifi, I just turn on wifi.
Otherwise I just have to be patient. My mobile data usage is rarely time-sensitive, so
I don't usually stress out about it. The only time I feel it's critical is when I'm using
the maps app for directions. That's the worst time to be left in the lurch.
There's no section at home that's a black hole for data, though you think there
would be, given the above.” - Jason, May 2011
33. Possible Solutions:
Form a grassroots set of folk to work up the hybrid server/client side solution for mobile browser and
feature detection as proposed in Brian Rieger’s presentation
Work with browser makers for a more complete feature profile and to alert of user preferences on
data, media, and current context.
We are all here now, what are we willing to accomplish & organize?
The Mobile Web is young, let’s keep the lines of
communication open and work together.
34. How To Get from Here to There
The Mobilism Presentations that Go in More Detail:
Steve Hay on Media Queries : http://slideshare.net/stephenhay/mobilism2011
Scott Jehl on Mobile JQuery (he will be posting this later after permission is gained)
Brian Rieger on Muddling Through the Mobile Web : http://slideshare.net/yiibu/
muddling-through-the-mobile-web
35. Resources:Text
W3C's Mobile Web Best Practices http://www.w3.org/TR/mobile-bp/
W3C's Mobile Web Application Best Practices http://www.w3.org/TR/mwabp/
W3C Media Queries http://www.w3.org/TR/css3-mediaqueries/
Global Authoring Practices for the Mobile Web http://www.passani.it/gap/
USC's Best Practices in Mobile Detection http://webservices.usc.edu/blog/development/mobile_detection/
Quirksmode Mobile http://quirksmode.org/mobile/
Detect Mobile Browser http://detectmobilebrowser.com/
Modernizr http://www.modernizr.com/
Simple javascript mobile OS detector http://blog.justin.kelly.org.au/simple-javascript-mobile-os-detector
WURFL http://wurfl.sourceforge.net/
Deploying WURFL http://wurfl.sourceforge.net/newapi/
Tera-WURFL UA & Feature Explorer http://tera-wurfl.com/explore/
James Pearce's Modernizr-server https://github.com/jamesgpearce/modernizr-server
The Switcher http://www.passani.it/switcher/
Manifesto for Responsible Reformatting http://wurfl.sourceforge.net/manifesto/
36. Thank you!
Jenifer Hanen :: Black Phoebe Designs
@msjen blackphoebe.com/msjen
Please watch twitter | blog for the Slideshare URL of this Presentation