Presentation from Jan. 12, 2011 meeting of Portland (Ore.) Drupal Users Group (PDXDUG). A whirlwind tour of mobile Web topics from a Drupal 6 viewpoint. As much as I could get into a 45-minute slide deck! Whew.
2. Where are we going today?
Mobile Web development theories and philosophies
Reality check!
Core tenets I like to stick to
So, about Drupal...the good and the bad
Digging in and putting some pieces together (CODE!)
Stuff to read so you can learn more
Thursday, January 13, 2011
3. How technical is this going to be?
Weāll start high level (everyone)
Weāll talk about strategy and device grouping (everyone/solution architects)
Weāll talk about Drupalās strengths and weaknesses and 3rd-party stuff.
(everyone/somewhat technical)
Weāll look at code for a hypothetical module and work with Drupal hooks and
whatnot. (devs/code)
Weāll talk about mobile theming strategy. (designers)
Iāll recommend some books, blogs and mailing lists. (everyone)
Thursday, January 13, 2011
4. Nope.
This topic is huge. We wonāt have time to talk about:
Detailed (HTML/CSS) markup for mobile devices.
The ļ¬ner points of device-speciļ¬c support for
technologies (CSS/JS/HTML5/whatever).
Design and UX best practices.
Testing.
All of these areas are incredibly important,
though!
Thursday, January 13, 2011
5. By The Way
This presentation is
based on Drupal 6
My current feeling about D7*
* Sorry
Thursday, January 13, 2011
8. One Web means making, as far as is reasonable, the
same information and services available to users
irrespective of the device they are using. However, it
does not mean that exactly the same information is available in
exactly the same representation across all devices. The context
of mobile use, device capability variations, bandwidth issues and
mobile network capabilities all affect the representation...
...it is considered best practice to provide as reasonable
experience as is possible given device limitations and not to
exclude access from any particular class of device, except
where this is necessary because of device
limitations....
Errr...
Thursday, January 13, 2011
9. That means...
Separate mobile site or domain (e.g. m.mysite.com) is
discouraged.
All users should get, for the most part, the same text,
features, markup, images, functionality, etc. (within
reason, which you get to determine).
Develop once (I do like this part).
Thursday, January 13, 2011
11. RWD
Using sophisticated markup and CSS techniques to
make the āOne Webā ideal more attainable.
Using CSS Media Queries to adapt content, allowing
for āOne Webā success
Fluid grid designs
For the most part, send the same HTML markup and
media (e.g. images) to everyone
http://www.alistapart.com/articles/responsive-web-
design/
Thursday, January 13, 2011
12. I am a CSS Media Query:
<link rel="stylesheet" type="text/css"
media="screen and (max-device-width: 480px)"
href="shetland.css" />
Thursday, January 13, 2011
14. Progressive Enhancement
Not just a mobile concern
Luke Wās āMobile Firstā credo is in the same family
Design your baseline site for mobile, then go from
there
http://www.lukew.com/ff/entry.asp?933
Thursday, January 13, 2011
17. Server-Side Device Detection
Based on using User Agent strings to make an
educated guess at what a device is and what
capabilities it has
Several device libraries support this. Two of the best
known are:
WURFL
DeviceAtlas
Thursday, January 13, 2011
18. WURFL
http://wurļ¬.sourceforge.net/
Maintained/moderated by Luca Passani.
Exhaustive details about mobile device and client
capabilities based on User Agent.
Contributors have created APIs in several languages.
Free and open source.
Thursday, January 13, 2011
19. Letās Look at some WURFL Capabilities
Tera-WURFL Explorer
http://www.tera-wurļ¬.com/explore/
Thursday, January 13, 2011
20. DeviceAtlas
Licenses run from $99/yr (per server) to ... well, more.
You get guaranteed updates.
API is PHP, Java, .Net
Analytics as well.
Web site is free and a useful reference for looking up
devices right quick.
http://deviceatlas.com
Thursday, January 13, 2011
24. Client-Side Adaptation
Determining real client capabilities a la Modernizr
Using CSS Media queries
Taking delivered markup the ļ¬nal mile
Ensures that the client can walk the walk
Thursday, January 13, 2011
25. Modernizr (A Quick Aside)
Runs tests on the client
Adds CSS classes to the <html> element based on
what it discovers
You, noble developer/themer, can:
Write your CSS accordingly
Use JavaScript to extend your stuff
Based on what the browser can actually do
http://www.modernizr.com
Thursday, January 13, 2011
26. So, that all sounds lovely and clean and
unicorn-shaped.
Thursday, January 13, 2011
29. āOne Webā is vague
Dear Puny Human,
Make one Web site such that itās, like, the same on all devices,
except, well, make sure that it is appropriately different on some
devices. Donāt exclude anyone, except when ādevice limitationsā
force you to.
Iāll leave deciding what a device limitation is as an exercise for
the reader.
Love,
The W3C
http://www.w3.org/TR/mobile-bp/#OneWeb
Thursday, January 13, 2011
30. RWD has performance and bandwidth implications
Image resizing on devices can be inefļ¬cient and uses
bandwidth you might not need to use.
CSS media query support is fragmented and only on
modern devices.
For the most part, images hidden in CSS still get
downloaded.
Weāre sending the device bytes that it is not going to
use.
http://www.cloudfour.com/css-media-query-for-mobile-
is-fools-gold/
Thursday, January 13, 2011
31. Shoving a 153,600-pixel image at a phone that only has about
16,000 pixels of real estate to work with is like giving 4-by-8-
foot sheets of plywood to a kid who wants to build a miniature
birdhouse. Even if wood is cheap, it tastelessly wastes a lot of
trees...
āLyza Gardner (Me)
Adventures on the Mobile Web Frontier, Nov. 4, 2010
*
http://www.cloudfour.com/adventures-on-the-mobile-web-frontier-wrangling-
drupal-third-party-apis-and-server-oomph-into-an-enterprise-class-
experience/
* Sorry about that URL; my bad
Thursday, January 13, 2011
32. Server-side device detection via UA is not infallible...
Who goes
there?
Hello, Web
Server, I am a
sheep!
Thursday, January 13, 2011
33. Who goes
there?
Web Server! I am
also a sheep!*
*Not really a sheep.
Thursday, January 13, 2011
34. Client-side enhancement can be pretty tricky if your
userās device isnāt up to it
āHi, Iām BlackBerry version 4.5. Youād be
surprised at how many people at big
companies still use me and love me.
You cannot manipulate my DOM and my
JavaScript performance is very sad.
Sorry.ā
Thursday, January 13, 2011
36. Duct Tape Programming
āDuct tape programmers are pragmatic...
āA 50%-good solution that people actually have solves more problems and survives
longer than a 99% solution that nobody has because itās in your lab where youāre
endlessly polishing the damn thing.
āShipping is a feature. A really important
feature. Your product must have it.ā
āJoel Spolsky
The Duct Tape Programmer, Sept. 23, 2009
Joel on Software
http://www.joelonsoftware.com/items/2009/09/23.html
Thursday, January 13, 2011
41. 2. The client is always
right*
* This one gets me in a bit of trouble
Thursday, January 13, 2011
42. Remember how I said that User Agents
arenāt always 100% honest and
forthcoming? Or, at least, sane?
Thursday, January 13, 2011
43. Whose User Agent is this?
Mozilla/5.0 (Macintosh; U; Intel Mac OS X
10_5_7; en-us) AppleWebKit/530.17 (KHTML, like
Gecko) Version/4.0
Safari/530.17
Thursday, January 13, 2011
44. A Sane Person would guess...
Desktop Safari
And thatās what WURFL will tell you, too
Thursday, January 13, 2011
45. But
Itās Skyļ¬re for Android.
Thursday, January 13, 2011
46. āLoad web pages as either traditional Android user agent or as
a desktop browser. The desktop option gives you more
ļ¬exibility in accessing web sites and allows discovery of video
content that might not be visible on the mobile site.ā
Laughing all the way to the Bank or whatever,
Love,
Skyļ¬re
Skyļ¬re Web Site
http://www.skyļ¬re.com/product/android
Thursday, January 13, 2011
47. What do we do?!
So, the User Agent for Skyļ¬reās desktop mode is cruel
and manipulative.
What should we do?
Me: Give them the desktop experience. They asked
for it. If it sucks enough for enough people, Skyļ¬re
will hopefully adapt.
This is not a universally-embraced opinion, to say the
least. And leaves some folks out in the cold.
What do you think?
Thursday, January 13, 2011
50. Device Classes
A device class is a collection of attributes and
capabilities that deļ¬ne a group of mobile devices.
There are no industry-standard device classes, but
there are some rules of thumb and generalizations that
can help you deļ¬ne your device classes.
We usually end up with about 3-5 major device classes
per project.
Thursday, January 13, 2011
51. Device Classes: Why?
Keeps you sane.
Helps you focus on your target users.
Gives you a context to think within when designing UX
and IA for your site or app.
Roughly, device class == context
Thursday, January 13, 2011
52. Some Advice about Device Classes
Donāt get too distracted by pixel dimensions.
Choose your ābaselineā class carefully. Whoās your main
audience?
Youāve heard this nag before,: donāt assume everyone
has an iPhone or Android.
device class != theme/layout
Thursday, January 13, 2011
53. Example Device Classes
Device Class Criteria Notes
ā¢ Webkit-based browser
ā¢ Minimum resolution 320x480
āMobile Webkitā ā¢ Sophisticated CSS/JS/XHR
āThere is no Webkit on mobileā.
āPeter-Paul Koch, QuirksMode
support
ā¢ Resolution 240-320px
ā¢ Robust XHTML support Donāt neglect this class!
Smartphones ā¢ Reasonable AJAX and JS BB5, Win 6.x, etc.
ā¢ Quite possibly less awesome CSS
ā¢ Resolution 128-240px
ā¢ HTML support a.k.a. feature
Dumbphones ā¢ Cookie/HTTPs support
ā¢ Limited CSS support phones
Thursday, January 13, 2011
54. And Then you draw the line somewhere
e.g. āFor a mobile device to be successful using this
Web-based application, it must support images,
cookies and HTTPs, and have a resolution of at least
128px.ā
Thursday, January 13, 2011
55. And the rest, you gently kick to the curb.
Gently.
Thursday, January 13, 2011
56. OK, Here comes the Drupal
part...
Thursday, January 13, 2011
58. Drupal is great because:
We can easily extend it by writing modules or using
those that others have kindly already written
The theming stack and hook architecture is
ļ¬exible enough that we can override almost anything
we need to
Sub-theming gives us even more power here
There are already some third-party modules that can
help us
Your site may already be running on it.
Thursday, January 13, 2011
60. Drupal makes kittens cry because:
Drupal 6 doesnāt have a deļ¬nitive hook for managing
CSS and JS
Theme inheritance can only go so far
WYSIWTF
There is no simple, 3rd-party solution you can just drop
into place. I bet there will be in the future. But.
Thursday, January 13, 2011
61. WYSIWTF
How the heck can your siteās editors
create content that will look right on all
devices?
CKEditor canāt save your butt here
Donāt blame Drupal per se: No one has
nailed this one
I donāt have a good answer for you
here...yet
Thursday, January 13, 2011
62. Everything you learn today is obsolete tomorrow
Case in point: This just in!
http://drupal.org/project/tinysrc
Thursday, January 13, 2011
64. mobile tools
A lot of stuff in this module, and it can integrate with WURFL or BrowserCap.
These are your device classes. Take āem or leave āem.
function mobile_tools_device_groups() {
Ā return array('iphone', 'ipod', 'android', 'opera mini', 'blackberry');
}
āThe Mobile Tools module currently doesn't provide information on the device
characteristics such as screen size, browser capabilities, javascript support,
etc ...ā (from the project page)
Generally, I ļ¬nd that I want a bit more control than this module gives me, but it
could serve as a great starting point.
Thursday, January 13, 2011
65. wurļ¬
Uses PHP API
Recent rewrite...not backwards compatible so much.
UGH.
Doesnāt expose everything from the PHP API, but does
encapsulate some.
Multiple sites? Youāll be replicating the WURFL data.
Install process is a bit painful.
But, overall, a good place to start, and weāll be using it
in our examples tonight.
Thursday, January 13, 2011
68. We are going to...
Use and depend on the wurļ¬ module
Create our own module
Detect Devices
Switch Themes
Create and implement a Device Class Deļ¬nition hook
Deļ¬ne some device classes
Test devices against deļ¬ned device classes
Create some mobile themes
Add some useful code to our themes to strip certain JS and CSS
Thursday, January 13, 2011
69. Disclaimer!
OMG! Donāt take this code too literally. Itās
meant as:
A. A stepping-off point and
B. Pseudo-code
It is based on real code (which has been tested) but
has not been tested in its current form.
You donāt have to implement it this way! These are
just rough ideas for yah.
Thursday, January 13, 2011
71. First Pass at the hook_init()
Thursday, January 13, 2011
72. Create a Hook for Device Classes
Thursday, January 13, 2011
73. Device Class Deļ¬nitions
This can be read:
((is_wireless_device == TRUE) &&
(ajax_xhr_type != ānoneā) &&
(mobile_browser === āSafariā ||
mobile_browser === āAndroid Webkitā))
Thursday, January 13, 2011
74. Deļ¬ne some Device Classes
In the interest of brevity, only two device
classes here and āWebkit on Mobileā is
over-simplified.
Thursday, January 13, 2011
76. Matching Device Classes
Get the code for mobile_web_device_match(), if you
want it, at http://pastebin.com/jtufBq38
Returns TRUE if the current set of device class
capabilities match the current userās device
Thursday, January 13, 2011
78. Creating some Themes
Consider your DOCTYPE
Familiarize yourself with whatās supported in XHTML-
MP
Drupal-speciļ¬c gotcha: Youāll need to override
theme(ātableā) if you want your code to validate in
XHTML-MP 1.2 (<thead> is invalid).
You can mostly disregard WML these days.
I sub-theme quite a bit (http://drupal.org/node/
225125)
Thursday, January 13, 2011
79. Might I suggest?
Iām a big fan of sub-themes.
Thursday, January 13, 2011
80. Another Variant
For hybrid desktop/mobile sites.
I also advise using the admin_theme module such that
the admin interface stays sane.
Thursday, January 13, 2011
81. Donāt Panic!
Youāre not going to have to implement full-ļ¬edged
themes for all of your devices!
Our device class themes usually contain:
Additional CSS for that device class (in addition to
default mobile or overrides)
Device-class-speciļ¬c JS
Overrides for templates on an as-needed basis.
Thursday, January 13, 2011
82. My CSS and JS are Out of Control!
In D6, theme has ļ¬nal say-so of what
JS and CSS get delivered
First call to drupal_add_js() always
adds jQuery and drupal.js
Iāll show you how to get around
this, but it is ugly
A brief D7 interlude: This is remedied
in D7 with two new alter hooks for
CSS and JS
Thursday, January 13, 2011
83. Control your JS and CSS
Youāll have to do this in a themeās template.php ļ¬le.
If you have themes subclassed from a single mobile
theme, you can put this in one place (the top-level
mobile theme).
I do it from a hook_preprocess_page(&$vars)
implementation.
Thursday, January 13, 2011
84. Stripping JS and CSS
The premise of the code is:
Declare some JS (or CSS) that is allowed for the mobile theme at hand.
Iterate through the JS in the āscriptsā var (all current JS/CSS set up to be in the
page) and make sure each entry is āallowed.ā
Remove those that are not.
For JS, if only drupal.js and jQuery.js are left at the end, remove those, too.
Re-set the āscriptsā var by calling drupal_get_js() with the updated array of JS (or
the same concept with CSS).
Thursday, January 13, 2011
85. Simplest Way to strip Extra JS...
The same approach works for CSS (the
āstylesā variable).
Thursday, January 13, 2011
88. Where to from here?
Use the device class to help determine how theme
functions behave, both on the theme level and module
levels.
Use the imagecache module to serve appropriately-sized
images to different device classes (or maybe tinysrc!).
Expand device class deļ¬nitions to add any sort of
arbitrary data youād like.
Keep a WURFL object (or other data structure
representing the WURFL attributes) available; you can ask
about a deviceās speciļ¬c capabilities anywhere in your
code.
Thursday, January 13, 2011
89. Exercises for the Reader
Some things weāve done to make this stuff cooler:
Build an admin interface for managing allowed CSS/
JS and other goodies.
Build logging to capture User Agents and their device
class results (might not want to leave this on in
production!)
Consider running a Tera-WURFL setup.
Thursday, January 13, 2011
90. Where are things heading?
More client-based stuff as mobile browsers get beeļ¬er
More 3rd-party Drupal support
This era is kind of like the JavaScript browser insanity
of the late 90s
Thursday, January 13, 2011
92. Read these books and blogs
Programming the Mobile Web
Maximiliano Firtman (OāReilly)
Beginning Smartphone Web Development
Gail Rahn Frederick/Rajesh Lal (Apress)
Because JS is Important for mobile:
High Performance JavaScript
Nicholas C. Zakas (OāReilly)
JavaScript: The Good Parts
Douglas Crockford (OāReilly)
Thursday, January 13, 2011
93. Read these books and blogs
QuirksBlog by PPK (Peter-Paul Koch)
http://www.quirksmode.org/blog/
Andrea Trasattiās tech notes and more
http://blog.trasatti.it/
Communities Dominate Brands (Tomi Ahonen)
http://communities-dominate.blogs.com/brands/
Luke Wroblewski aka @lukew
http://www.lukew.com/ff/
Thursday, January 13, 2011
94. Super Useful Groups & Mailing Lists
mobile-web Yahoo! Group
http://tech.groups.yahoo.com/group/mobile-web
An active, useful list
wmlprogramming Yahoo! Group
http://tech.groups.yahoo.com/group/wmlprogramming
Despite the misleading name, this mailing list focuses
on WURFL. Expect a rollicking time.
Mobile Portland
http://mobileportland.com/
http://groups.google.com/group/mobile-portland
Meets the fourth Monday of each month
Thursday, January 13, 2011
95. Who Am I?
Lyza Danger Gardner
co-founder, mobile Web developer type of person
Cloud Four
http://www.cloudfour.com
http://www.lyza.com
@lyzadanger
Thursday, January 13, 2011