The Contextual Experience of the Mobile Web

Jeff Carouth
Jeff CarouthApplication Developer, Self-employed consultant
The Contextual Experience
                    of the Mobile Web
                                    Jeff Carouth
                              ZendCon, October 19, 2011




Wednesday, October 19, 2011
Howdy!


                        (Yeah, I’m from Texas.)
                        PHP Developer since 2003
                        Web and mobile developer at Texas
                        A&M University



Wednesday, October 19, 2011
This is not a presentation
                      about development…



Wednesday, October 19, 2011
…nor is it about design…




Wednesday, October 19, 2011
…it’s about the collision of
                the two on the mobile web.



Wednesday, October 19, 2011
The Big Three

                    The context of the mobile web is the
                    specific environment and expectations
                      a user or visitor of your website or
                       application brings when he or she
                     accesses it while mobile or using a
                                mobile device.


Wednesday, October 19, 2011
Environment, expectations, and intent

                              Mobile and mobility

                              Devices and capabilities




Wednesday, October 19, 2011
In my opinion, design plays
                     a major role in mobile
                            success.



Wednesday, October 19, 2011
Wednesday, October 19, 2011
Wednesday, October 19, 2011
The question then becomes
                how can you accommodate
                  both a 27” iMac and an
                          iPhone?


Wednesday, October 19, 2011
Or, more accurately, how
                       can you accommodate
                        browsers of differing
                              widths?


Wednesday, October 19, 2011
Obvious Answer: Layouts




Wednesday, October 19, 2011
Option–redirect




Wednesday, October 19, 2011
User Agent sniffing


                              If UA indicates mobile device
                               redirect to separate mobile site, or
                                provide a link to a separate mobile
                               site



Wednesday, October 19, 2011
function mobile_device_detect(/* bunch of params */) {
      $mobile_browser   = false;
      $user_agent       = $_SERVER['HTTP_USER_AGENT'];
      $accept           = $_SERVER['HTTP_ACCEPT'];

             switch(true){
                 case (preg_match('/ipad/i',$user_agent));
                     $mobile_browser = $ipad;
                     $status = 'Apple iPad';
                     if(substr($ipad,0,4)=='http'){
                         $mobileredirect = $ipad;
                     }
                 break;
             }

             if($mobile_browser==true){
                 header('Location: '.$redirect);
                 exit;
             }
  }                           http://detectmobilebrowsers.mobi
Wednesday, October 19, 2011
Or Show A Link




Wednesday, October 19, 2011
Problems with this method


                              Perhaps your user wants your full site.
                          They’ll likely miss any links
                               and alert boxes are terrible.




Wednesday, October 19, 2011
Option–layout switching




Wednesday, October 19, 2011
function is_mobile() {
      $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']);
      if (in_array(
          substr($user_agent, 0, 4),
          array('ipod','cell',...))) {
        return true;
      }
      if (strpos($_SERVER['HTTP_ACCEPT'], 'wap') != false) {
        return true;
      }
      if (preg_match(
          "/(android|blackberry|ipod|palm|...))/i",
          $user_agent)) {
        return true;
      }
      return false;
    }



Wednesday, October 19, 2011
if (is_mobile()) {
        require_once "mobile-layout.php";
    } else {
        require_once "desktop-layout.php";
    }




Wednesday, October 19, 2011
That’s very basic, and
                               largely unreliable.



Wednesday, October 19, 2011
We can use a device
                        database to improve the
                         accuracy of matches.



Wednesday, October 19, 2011
Choices


                        WURFL (Wireless Universal Resource
                        FiLe)
                              Device Atlas




Wednesday, October 19, 2011
class Bootstrap
        extends Zend_Application_Bootstrap_Abstract
    {
        protected function _mobileLayoutSwitch() {
            $this->bootstrap('useragent');
            $this->bootstrap('layout');
            $uaType = $this->getResource('useragent')
                            ->getDevice()
                            ->getType();
            if ($uaType === 'mobile') {
                $this->getResource('layout')
                    ->setLayout('mobile');
            }
        }
    }




Wednesday, October 19, 2011
protected function _mobileLayoutSwitch() {
        $this->bootstrap('useragent');
        $this->bootstrap('layout');
        $resolution = $this->getResource('useragent')
                        ->getDevice()
                        ->getFeature('resolution_width');
        if ($resolution < 320) {
            $layout = 'poor';
        } elseif ($resoution < 480) {
            $layout = 'medium';
        } else {
            $layout = 'desktop';
        }
        $this->getResource('layout')->setLayout($layout);
    }




Wednesday, October 19, 2011
It works…


                              But we can do better.
                         We can apply the mantra: “branch on
                        features not user agents” to our
                        mobile layouts.



Wednesday, October 19, 2011
The problem with user
                                agents is: they lie.



Wednesday, October 19, 2011
Option–responsive layout




Wednesday, October 19, 2011
So, how many of you
                        remember liquid or fluid
                                layouts?



Wednesday, October 19, 2011
Responsive breakpoints




Wednesday, October 19, 2011
Techniques

                 All in one CSS file
                 Base CSS file and one CSS file for each
                class of device
                       Major breakpoints in <link> media
                      attribute
                        Minor breakpoints in device stylesheet


Wednesday, October 19, 2011
<link rel=stylesheet type=text/css
        href=styles/base.css media="screen,handheld" />

    <link rel=stylesheet type=text/css
        href=styles/mobile.css
        media="only screen and (min-width: 320px)" />

    <link rel=stylesheet type=text/css
        href=styles/desktop.css
        media="only screen and (min-width: 720px)" />



    /****** mobile.css ******/
    @media screen and (min-width: 480px) {
        /* styles for this class of mobile browser */
    }

    @media screen and (min-width: 640px) {
        /* iPad maybe? */
    }
Wednesday, October 19, 2011
Desktop and iPad




Wednesday, October 19, 2011
A couple mobile devices


       iPhone 3GS                           iPhone 4
                                Nexus One




Wednesday, October 19, 2011
That’s great, but we haven’t
                   really solved the device
                          context yet.



Wednesday, October 19, 2011
Problem: limited bandwidth




Wednesday, October 19, 2011
All we adjusted for is width


                         Images are the same size for desktops
                        as they are for mobile
                          This is bad.Very bad.
                              Solution?



Wednesday, October 19, 2011
JavaScript-based image
                                       resize




                                            Credit: http://jedimsieer.deviantart.com/
Wednesday, October 19, 2011
<img src="images/sample-small.jpg?full=images/sample-
    large.jpg" />

    (function(win) {
      /* code */
      var loadLarge = win.screen.availWidth > 480;
      if (!loadLarge) {
        return;
      }
      // more code...
      imgs = document.getElementsByTagName("img");
      for ( var i = 0, il = imgs.length; i < il; i++) {
          src = imgs[i].getAttribute("src");
          fullImgSrc = src.match( /(?|&)full=(.*)&?/ ) && RegExp.$2;
          if( fullImgSrc ) {
              imgs[i].src = fullImgSrc;
          }
      }
      //more code...
    })(this);


                              https://github.com/filamentgroup/Responsive-Images

Wednesday, October 19, 2011
Alternative


                              Do the work on the server.
                         (You know, like in the 1990s when
                        JavaScript was Evil(tm))




Wednesday, October 19, 2011
The Process

                   Device requests page from server.
                  Service asks device for its device profile
                 (cookie?)
                   No profile available, build one from base.
                   Load resources based on profile.
                   Deliver content AND profile to device.

Wednesday, October 19, 2011
I haven’t seen this
                              implemented yet.



Wednesday, October 19, 2011
The mobility context




Wednesday, October 19, 2011
Wednesday, October 19, 2011
The Go To Example


                        Geolocation
                        i.e., driving directions or stores near
                        me




Wednesday, October 19, 2011
Do you trust directions
                           from my site, or from
                              Google Maps?



Wednesday, October 19, 2011
Right. I use Google Maps
                                   too.



Wednesday, October 19, 2011
So let’s use geolocation for
                        something else.



Wednesday, October 19, 2011
Working on a CRM


                              Sales agent travels to Switzerland
                         Give a listing of leads/customers in
                        the area.




Wednesday, October 19, 2011
HTML5 Geolocation API

     if (navigator.geolocation) {
         navigator.geolocation.getCurrentPosition(
             function (position) {
                 callGeonamesWebservice(
                     position.coords.latitude,
                     position.coords.longitude);
             },
             function (error) {
                 //handle error
             }
         );
     }



Wednesday, October 19, 2011
<geonames>
        <code>
            <postalcode>8775</postalcode>
            <name>Luchsingen</name>
            <countryCode>CH</countryCode>
            <lat>46.98017</lat>
            <lng>8.99868</lng>
            <adminCode1/>
            <adminName1/>
            <adminCode2/>
            <adminName2/>
            <adminCode3>1631</adminCode3>
            <adminName3/>
            <distance>2.2072</distance>
        </code>
    </geonames>




Wednesday, October 19, 2011
Fetch Data From Your App




Wednesday, October 19, 2011
function findCustomersByPostalCode(
            $postalCodes,
            $recency) {
        //some SQL
        //where postal_code in $postalCodes
        //and last_contact between $recency and today

               return $customers;
    }




Wednesday, October 19, 2011
That’s just one example.
            Mobility context is absolutely
                application-specific



Wednesday, October 19, 2011
Recap

                         Many options for dealing with device
                        context
                              User Agent sniffing
                               Redirect
                               Layout switch
                              Responsive design

Wednesday, October 19, 2011
Recap (cont.)


                         Users want to complete a task, not
                        always informative in nature.
                         Mobile is quickly shifting from a nice-
                        to-have to a must have component of
                        your projects.



Wednesday, October 19, 2011
What about jQuery Mobile
                    and other mobile
                       frameworks?



Wednesday, October 19, 2011
Thank you!




Wednesday, October 19, 2011
Questions?

                              Contact me
                               jcarouth@gmail.com
                               @jcarouth
                               jcarouth on Freenode
                              Rate at: http://joind.in/3786


Wednesday, October 19, 2011
1 of 60

Recommended

Von Dinosauriern, Bienen und Wespen by
Von Dinosauriern, Bienen und WespenVon Dinosauriern, Bienen und Wespen
Von Dinosauriern, Bienen und WespenTomas Caspers
1.3K views74 slides
Practical PHP 5.3 by
Practical PHP 5.3Practical PHP 5.3
Practical PHP 5.3Nate Abele
7K views48 slides
Symfony2 - from the trenches by
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
3.3K views43 slides
The top 10 web application intrusion techniques by
The top 10 web application intrusion techniquesThe top 10 web application intrusion techniques
The top 10 web application intrusion techniquesAntonio Fontes
2.5K views80 slides
Develop and deploy using Hybrid Cloud Strategies confoo2012 by
Develop and deploy using Hybrid Cloud Strategies confoo2012Develop and deploy using Hybrid Cloud Strategies confoo2012
Develop and deploy using Hybrid Cloud Strategies confoo2012Combell NV
1.4K views95 slides
Taming the Deployment Beast by
Taming the Deployment BeastTaming the Deployment Beast
Taming the Deployment BeastChris Cornutt
1.7K views24 slides

More Related Content

Similar to The Contextual Experience of the Mobile Web

A Look at the Future of HTML5 by
A Look at the Future of HTML5A Look at the Future of HTML5
A Look at the Future of HTML5Tim Wright
10K views41 slides
Mobile Accessibility - Accessibility Camp Toronto by
Mobile Accessibility - Accessibility Camp TorontoMobile Accessibility - Accessibility Camp Toronto
Mobile Accessibility - Accessibility Camp TorontoTed Drake
4.6K views58 slides
ISA11 - Bill Scott - Designing Mice Men by
ISA11 - Bill Scott - Designing Mice MenISA11 - Bill Scott - Designing Mice Men
ISA11 - Bill Scott - Designing Mice MenInteraction South America
1.7K views137 slides
Brian Hogg - Web Apps using HTML5 and JS by
Brian Hogg - Web Apps using HTML5 and JSBrian Hogg - Web Apps using HTML5 and JS
Brian Hogg - Web Apps using HTML5 and JS#DevTO
659 views13 slides
Cross-Platform, Native Mobile Development with a DSL by
Cross-Platform, Native Mobile Development with a DSLCross-Platform, Native Mobile Development with a DSL
Cross-Platform, Native Mobile Development with a DSLPeter Friese
1.3K views32 slides
Boston Globe: Responsive Web Design by
Boston Globe: Responsive Web DesignBoston Globe: Responsive Web Design
Boston Globe: Responsive Web DesignThe Media Consortium
12.2K views52 slides

Similar to The Contextual Experience of the Mobile Web(20)

A Look at the Future of HTML5 by Tim Wright
A Look at the Future of HTML5A Look at the Future of HTML5
A Look at the Future of HTML5
Tim Wright10K views
Mobile Accessibility - Accessibility Camp Toronto by Ted Drake
Mobile Accessibility - Accessibility Camp TorontoMobile Accessibility - Accessibility Camp Toronto
Mobile Accessibility - Accessibility Camp Toronto
Ted Drake4.6K views
Brian Hogg - Web Apps using HTML5 and JS by #DevTO
Brian Hogg - Web Apps using HTML5 and JSBrian Hogg - Web Apps using HTML5 and JS
Brian Hogg - Web Apps using HTML5 and JS
#DevTO659 views
Cross-Platform, Native Mobile Development with a DSL by Peter Friese
Cross-Platform, Native Mobile Development with a DSLCross-Platform, Native Mobile Development with a DSL
Cross-Platform, Native Mobile Development with a DSL
Peter Friese1.3K views
Developing a Progressive Mobile Strategy (Key Comm Version) by Dave Olsen
Developing a Progressive Mobile Strategy (Key Comm Version)Developing a Progressive Mobile Strategy (Key Comm Version)
Developing a Progressive Mobile Strategy (Key Comm Version)
Dave Olsen1.3K views
Intro to Web Apps using HTML5 and Javascript by Brian Hogg
Intro to Web Apps using HTML5 and JavascriptIntro to Web Apps using HTML5 and Javascript
Intro to Web Apps using HTML5 and Javascript
Brian Hogg379 views
Mobile Web on Drupal! by Lyza Gardner
Mobile Web on Drupal!Mobile Web on Drupal!
Mobile Web on Drupal!
Lyza Gardner5.6K views
Building Mobile Apps in WordPress - WordCamp Toronto 2011 by Trevor Mills
Building Mobile Apps in WordPress - WordCamp Toronto 2011Building Mobile Apps in WordPress - WordCamp Toronto 2011
Building Mobile Apps in WordPress - WordCamp Toronto 2011
Trevor Mills2.2K views
Fall11 Day 9 - Location Based & Mobile Marketing by Andrew Hoffman
Fall11 Day 9 - Location Based & Mobile MarketingFall11 Day 9 - Location Based & Mobile Marketing
Fall11 Day 9 - Location Based & Mobile Marketing
Andrew Hoffman1.3K views
So, you think you know widgets. by danielericlee
So, you think you know widgets.So, you think you know widgets.
So, you think you know widgets.
danielericlee3.3K views
BlackBerry WebWorks APIs by Sencha
BlackBerry WebWorks APIsBlackBerry WebWorks APIs
BlackBerry WebWorks APIs
Sencha1.5K views
We're not designing posters, here! by André Luís
We're not designing posters, here!We're not designing posters, here!
We're not designing posters, here!
André Luís1.9K views

Recently uploaded

DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...ShapeBlue
141 views29 slides
Business Analyst Series 2023 - Week 4 Session 8 by
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8DianaGray10
145 views13 slides
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlueShapeBlue
152 views23 slides
Future of Indian ConsumerTech by
Future of Indian ConsumerTechFuture of Indian ConsumerTech
Future of Indian ConsumerTechKapil Khandelwal (KK)
36 views68 slides
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOsPriyanka Aash
162 views59 slides
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...ShapeBlue
183 views18 slides

Recently uploaded(20)

DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue141 views
Business Analyst Series 2023 - Week 4 Session 8 by DianaGray10
Business Analyst Series 2023 -  Week 4 Session 8Business Analyst Series 2023 -  Week 4 Session 8
Business Analyst Series 2023 - Week 4 Session 8
DianaGray10145 views
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue by ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue152 views
Digital Personal Data Protection (DPDP) Practical Approach For CISOs by Priyanka Aash
Digital Personal Data Protection (DPDP) Practical Approach For CISOsDigital Personal Data Protection (DPDP) Practical Approach For CISOs
Digital Personal Data Protection (DPDP) Practical Approach For CISOs
Priyanka Aash162 views
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue183 views
NTGapps NTG LowCode Platform by Mustafa Kuğu
NTGapps NTG LowCode Platform NTGapps NTG LowCode Platform
NTGapps NTG LowCode Platform
Mustafa Kuğu437 views
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software184 views
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue by ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlueVNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
VNF Integration and Support in CloudStack - Wei Zhou - ShapeBlue
ShapeBlue207 views
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And... by ShapeBlue
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
Enabling DPU Hardware Accelerators in XCP-ng Cloud Platform Environment - And...
ShapeBlue108 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc176 views
"Package management in monorepos", Zoltan Kochan by Fwdays
"Package management in monorepos", Zoltan Kochan"Package management in monorepos", Zoltan Kochan
"Package management in monorepos", Zoltan Kochan
Fwdays34 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue247 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue162 views
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ... by ShapeBlue
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
How to Re-use Old Hardware with CloudStack. Saving Money and the Environment ...
ShapeBlue171 views
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue by ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue139 views
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023 by BookNet Canada
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
Redefining the book supply chain: A glimpse into the future - Tech Forum 2023
BookNet Canada44 views
LLMs in Production: Tooling, Process, and Team Structure by Aggregage
LLMs in Production: Tooling, Process, and Team StructureLLMs in Production: Tooling, Process, and Team Structure
LLMs in Production: Tooling, Process, and Team Structure
Aggregage57 views
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue by ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue265 views

The Contextual Experience of the Mobile Web

  • 1. The Contextual Experience of the Mobile Web Jeff Carouth ZendCon, October 19, 2011 Wednesday, October 19, 2011
  • 2. Howdy! (Yeah, I’m from Texas.) PHP Developer since 2003 Web and mobile developer at Texas A&M University Wednesday, October 19, 2011
  • 3. This is not a presentation about development… Wednesday, October 19, 2011
  • 4. …nor is it about design… Wednesday, October 19, 2011
  • 5. …it’s about the collision of the two on the mobile web. Wednesday, October 19, 2011
  • 6. The Big Three The context of the mobile web is the specific environment and expectations a user or visitor of your website or application brings when he or she accesses it while mobile or using a mobile device. Wednesday, October 19, 2011
  • 7. Environment, expectations, and intent Mobile and mobility Devices and capabilities Wednesday, October 19, 2011
  • 8. In my opinion, design plays a major role in mobile success. Wednesday, October 19, 2011
  • 11. The question then becomes how can you accommodate both a 27” iMac and an iPhone? Wednesday, October 19, 2011
  • 12. Or, more accurately, how can you accommodate browsers of differing widths? Wednesday, October 19, 2011
  • 15. User Agent sniffing If UA indicates mobile device redirect to separate mobile site, or provide a link to a separate mobile site Wednesday, October 19, 2011
  • 16. function mobile_device_detect(/* bunch of params */) { $mobile_browser = false; $user_agent = $_SERVER['HTTP_USER_AGENT']; $accept = $_SERVER['HTTP_ACCEPT']; switch(true){ case (preg_match('/ipad/i',$user_agent)); $mobile_browser = $ipad; $status = 'Apple iPad'; if(substr($ipad,0,4)=='http'){ $mobileredirect = $ipad; } break; } if($mobile_browser==true){ header('Location: '.$redirect); exit; } } http://detectmobilebrowsers.mobi Wednesday, October 19, 2011
  • 17. Or Show A Link Wednesday, October 19, 2011
  • 18. Problems with this method Perhaps your user wants your full site. They’ll likely miss any links and alert boxes are terrible. Wednesday, October 19, 2011
  • 20. function is_mobile() { $user_agent = strtolower($_SERVER['HTTP_USER_AGENT']); if (in_array( substr($user_agent, 0, 4), array('ipod','cell',...))) { return true; } if (strpos($_SERVER['HTTP_ACCEPT'], 'wap') != false) { return true; } if (preg_match( "/(android|blackberry|ipod|palm|...))/i", $user_agent)) { return true; } return false; } Wednesday, October 19, 2011
  • 21. if (is_mobile()) { require_once "mobile-layout.php"; } else { require_once "desktop-layout.php"; } Wednesday, October 19, 2011
  • 22. That’s very basic, and largely unreliable. Wednesday, October 19, 2011
  • 23. We can use a device database to improve the accuracy of matches. Wednesday, October 19, 2011
  • 24. Choices WURFL (Wireless Universal Resource FiLe) Device Atlas Wednesday, October 19, 2011
  • 25. class Bootstrap extends Zend_Application_Bootstrap_Abstract { protected function _mobileLayoutSwitch() { $this->bootstrap('useragent'); $this->bootstrap('layout'); $uaType = $this->getResource('useragent') ->getDevice() ->getType(); if ($uaType === 'mobile') { $this->getResource('layout') ->setLayout('mobile'); } } } Wednesday, October 19, 2011
  • 26. protected function _mobileLayoutSwitch() { $this->bootstrap('useragent'); $this->bootstrap('layout'); $resolution = $this->getResource('useragent') ->getDevice() ->getFeature('resolution_width'); if ($resolution < 320) { $layout = 'poor'; } elseif ($resoution < 480) { $layout = 'medium'; } else { $layout = 'desktop'; } $this->getResource('layout')->setLayout($layout); } Wednesday, October 19, 2011
  • 27. It works… But we can do better. We can apply the mantra: “branch on features not user agents” to our mobile layouts. Wednesday, October 19, 2011
  • 28. The problem with user agents is: they lie. Wednesday, October 19, 2011
  • 30. So, how many of you remember liquid or fluid layouts? Wednesday, October 19, 2011
  • 32. Techniques All in one CSS file Base CSS file and one CSS file for each class of device Major breakpoints in <link> media attribute Minor breakpoints in device stylesheet Wednesday, October 19, 2011
  • 33. <link rel=stylesheet type=text/css href=styles/base.css media="screen,handheld" /> <link rel=stylesheet type=text/css href=styles/mobile.css media="only screen and (min-width: 320px)" /> <link rel=stylesheet type=text/css href=styles/desktop.css media="only screen and (min-width: 720px)" /> /****** mobile.css ******/ @media screen and (min-width: 480px) { /* styles for this class of mobile browser */ } @media screen and (min-width: 640px) { /* iPad maybe? */ } Wednesday, October 19, 2011
  • 34. Desktop and iPad Wednesday, October 19, 2011
  • 35. A couple mobile devices iPhone 3GS iPhone 4 Nexus One Wednesday, October 19, 2011
  • 36. That’s great, but we haven’t really solved the device context yet. Wednesday, October 19, 2011
  • 38. All we adjusted for is width Images are the same size for desktops as they are for mobile This is bad.Very bad. Solution? Wednesday, October 19, 2011
  • 39. JavaScript-based image resize Credit: http://jedimsieer.deviantart.com/ Wednesday, October 19, 2011
  • 40. <img src="images/sample-small.jpg?full=images/sample- large.jpg" /> (function(win) { /* code */ var loadLarge = win.screen.availWidth > 480; if (!loadLarge) { return; } // more code... imgs = document.getElementsByTagName("img"); for ( var i = 0, il = imgs.length; i < il; i++) { src = imgs[i].getAttribute("src"); fullImgSrc = src.match( /(?|&)full=(.*)&?/ ) && RegExp.$2; if( fullImgSrc ) { imgs[i].src = fullImgSrc; } } //more code... })(this); https://github.com/filamentgroup/Responsive-Images Wednesday, October 19, 2011
  • 41. Alternative Do the work on the server. (You know, like in the 1990s when JavaScript was Evil(tm)) Wednesday, October 19, 2011
  • 42. The Process Device requests page from server. Service asks device for its device profile (cookie?) No profile available, build one from base. Load resources based on profile. Deliver content AND profile to device. Wednesday, October 19, 2011
  • 43. I haven’t seen this implemented yet. Wednesday, October 19, 2011
  • 46. The Go To Example Geolocation i.e., driving directions or stores near me Wednesday, October 19, 2011
  • 47. Do you trust directions from my site, or from Google Maps? Wednesday, October 19, 2011
  • 48. Right. I use Google Maps too. Wednesday, October 19, 2011
  • 49. So let’s use geolocation for something else. Wednesday, October 19, 2011
  • 50. Working on a CRM Sales agent travels to Switzerland Give a listing of leads/customers in the area. Wednesday, October 19, 2011
  • 51. HTML5 Geolocation API if (navigator.geolocation) { navigator.geolocation.getCurrentPosition( function (position) { callGeonamesWebservice( position.coords.latitude, position.coords.longitude); }, function (error) { //handle error } ); } Wednesday, October 19, 2011
  • 52. <geonames> <code> <postalcode>8775</postalcode> <name>Luchsingen</name> <countryCode>CH</countryCode> <lat>46.98017</lat> <lng>8.99868</lng> <adminCode1/> <adminName1/> <adminCode2/> <adminName2/> <adminCode3>1631</adminCode3> <adminName3/> <distance>2.2072</distance> </code> </geonames> Wednesday, October 19, 2011
  • 53. Fetch Data From Your App Wednesday, October 19, 2011
  • 54. function findCustomersByPostalCode( $postalCodes, $recency) { //some SQL //where postal_code in $postalCodes //and last_contact between $recency and today return $customers; } Wednesday, October 19, 2011
  • 55. That’s just one example. Mobility context is absolutely application-specific Wednesday, October 19, 2011
  • 56. Recap Many options for dealing with device context User Agent sniffing Redirect Layout switch Responsive design Wednesday, October 19, 2011
  • 57. Recap (cont.) Users want to complete a task, not always informative in nature. Mobile is quickly shifting from a nice- to-have to a must have component of your projects. Wednesday, October 19, 2011
  • 58. What about jQuery Mobile and other mobile frameworks? Wednesday, October 19, 2011
  • 60. Questions? Contact me jcarouth@gmail.com @jcarouth jcarouth on Freenode Rate at: http://joind.in/3786 Wednesday, October 19, 2011