quick & dirty mobile web with jquery mobile
DESCRIPTION
Want to make your site support the mobile web quickly? In this talk I show how to quickly add mobile to an existing website with jQuery Mobile. I also cover an easy way to do mobile device detection and redirection.TRANSCRIPT
Quick & Dirty Mobile Web with jQuery MobileTROY MILES - [email protected]
Saturday, November 10, 12
Sponsors
Saturday, November 10, 12
Our Agenda 3
Saturday, November 10, 12
Our Agenda
Why Mobile Web?
3
Saturday, November 10, 12
Our Agenda
Why Mobile Web? Why jQuery Mobile?
3
Saturday, November 10, 12
Our Agenda
Why Mobile Web? Why jQuery Mobile? 4 Ways to Add Mobile to Your Site
3
Saturday, November 10, 12
Our Agenda
Why Mobile Web? Why jQuery Mobile? 4 Ways to Add Mobile to Your Site Detecting A Mobile Device
3
Saturday, November 10, 12
Our Agenda
Why Mobile Web? Why jQuery Mobile? 4 Ways to Add Mobile to Your Site Detecting A Mobile Device Let’s Get Dirty!
3
Saturday, November 10, 12
Our Agenda
Why Mobile Web? Why jQuery Mobile? 4 Ways to Add Mobile to Your Site Detecting A Mobile Device Let’s Get Dirty! Next Steps
3
Saturday, November 10, 12
Our Agenda
Why Mobile Web? Why jQuery Mobile? 4 Ways to Add Mobile to Your Site Detecting A Mobile Device Let’s Get Dirty! Next Steps Summary
3
Saturday, November 10, 12
Why Mobile Web? 4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is
4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is 20% of Internet Users in the US & UK are Mobile Only
4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is 20% of Internet Users in the US & UK are Mobile Only In Some African & Asian Markets it is Over 50%
4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is 20% of Internet Users in the US & UK are Mobile Only In Some African & Asian Markets it is Over 50% Twitter began Showing Ads in April 2012
4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is 20% of Internet Users in the US & UK are Mobile Only In Some African & Asian Markets it is Over 50% Twitter began Showing Ads in April 2012
Mobile is Now Responsible for more than 50% of its Ad Revenue
4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is 20% of Internet Users in the US & UK are Mobile Only In Some African & Asian Markets it is Over 50% Twitter began Showing Ads in April 2012
Mobile is Now Responsible for more than 50% of its Ad Revenue A Campaign with P.F.Chang got 1 million clicks in its First 4 Days
4
Saturday, November 10, 12
Why Mobile Web?
Mobile is Where Growth Is 20% of Internet Users in the US & UK are Mobile Only In Some African & Asian Markets it is Over 50% Twitter began Showing Ads in April 2012
Mobile is Now Responsible for more than 50% of its Ad Revenue A Campaign with P.F.Chang got 1 million clicks in its First 4 Days 70% of Those Clicks Came From Mobile
4
Saturday, November 10, 12
What is jQuery Mobile?
A unified, HTML5-based user interface system for all popular mobile device platforms, built on the rock-solid jQuery and jQuery UI foundation. Its lightweight code is built with progressive enhancement, and has a flexible, easily theme-able design.
Requires jQuery.
5
Saturday, November 10, 12
Why jQuery Mobile? 6
Saturday, November 10, 12
Why jQuery Mobile?
Its Free
6
Saturday, November 10, 12
Why jQuery Mobile?
Its Free Its Easy to Learn
6
Saturday, November 10, 12
Why jQuery Mobile?
Its Free Its Easy to Learn It Extends HTML5
6
Saturday, November 10, 12
Why jQuery Mobile?
Its Free Its Easy to Learn It Extends HTML5 It Supports a Wide Range of Devices
6
Saturday, November 10, 12
Why jQuery Mobile?
Its Free Its Easy to Learn It Extends HTML5 It Supports a Wide Range of Devices It is Not Feature Rich
6
Saturday, November 10, 12
Why jQuery Mobile?
Its Free Its Easy to Learn It Extends HTML5 It Supports a Wide Range of Devices It is Not Feature Rich It is Not Performant
6
Saturday, November 10, 12
4 Ways to Add Mobile 7
Saturday, November 10, 12
4 Ways to Add Mobile
Have Two Separate Sites Have Single Site, With Separate Controllers Single Site, With Separate Views Responsive Design And yes, there are other ways
7
Saturday, November 10, 12
Have Two Separate Sites 8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start
8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start Difficult to Share Code and Resources Between Sites
8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start Difficult to Share Code and Resources Between Sites Quickly Can Become a Maintenance Monster
8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start Difficult to Share Code and Resources Between Sites Quickly Can Become a Maintenance Monster
Two Sites to Deploy
8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start Difficult to Share Code and Resources Between Sites Quickly Can Become a Maintenance Monster
Two Sites to Deploy Two Databases to Deploy
8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start Difficult to Share Code and Resources Between Sites Quickly Can Become a Maintenance Monster
Two Sites to Deploy Two Databases to Deploy Two Sites to Maintain
8
Saturday, November 10, 12
Have Two Separate Sites
Easy To Start Difficult to Share Code and Resources Between Sites Quickly Can Become a Maintenance Monster
Two Sites to Deploy Two Databases to Deploy Two Sites to Maintain Two Sites to Enhance
8
Saturday, November 10, 12
Have Single Site, With Separate Controllers
9
Saturday, November 10, 12
Have Single Site, With Separate Controllers
The Desktop & Mobile Sites Each Have Their Own Controllers
9
Saturday, November 10, 12
Have Single Site, With Separate Controllers
The Desktop & Mobile Sites Each Have Their Own Controllers Allows for Some Sharing of Resources
9
Saturday, November 10, 12
Have Single Site, With Separate Controllers
The Desktop & Mobile Sites Each Have Their Own Controllers Allows for Some Sharing of Resources Only One Deployment
9
Saturday, November 10, 12
Have Single Site, With Separate Controllers
The Desktop & Mobile Sites Each Have Their Own Controllers Allows for Some Sharing of Resources Only One Deployment Bugs in the Controller or View
9
Saturday, November 10, 12
Single Site, With Separate Views 10
Saturday, November 10, 12
Single Site, With Separate Views
Code in the Controller Decides Which View to Show
10
Saturday, November 10, 12
Single Site, With Separate Views
Code in the Controller Decides Which View to Show High Degree of Code Sharing
10
Saturday, November 10, 12
Single Site, With Separate Views
Code in the Controller Decides Which View to Show High Degree of Code Sharing Users Get Locked into an Experience
10
Saturday, November 10, 12
Single Site, With Separate Views
Code in the Controller Decides Which View to Show High Degree of Code Sharing Users Get Locked into an Experience
Users Hate Getting Stuck
10
Saturday, November 10, 12
Single Site, With Separate Views
Code in the Controller Decides Which View to Show High Degree of Code Sharing Users Get Locked into an Experience
Users Hate Getting Stuck Users Sometimes Want to View the Full Site on Their Smart Phone
10
Saturday, November 10, 12
Responsive Design 11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views
11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views Site Uses CSS to Dynamically Resize Itself
11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views Site Uses CSS to Dynamically Resize Itself When Done Right It Looks Amazing
11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views Site Uses CSS to Dynamically Resize Itself When Done Right It Looks Amazing Difficult To Do Right
11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views Site Uses CSS to Dynamically Resize Itself When Done Right It Looks Amazing Difficult To Do Right Has Performance Issues
11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views Site Uses CSS to Dynamically Resize Itself When Done Right It Looks Amazing Difficult To Do Right Has Performance Issues
The Scaling Is Done on the Client
11
Saturday, November 10, 12
Responsive Design
A Single Site With Single Controller and Views Site Uses CSS to Dynamically Resize Itself When Done Right It Looks Amazing Difficult To Do Right Has Performance Issues
The Scaling Is Done on the Client Entire Site Sent To The Client, But Much of it May Not Be Used
11
Saturday, November 10, 12
Responsive Design Sites 12
Saturday, November 10, 12
Responsive Design Sites
http://bostonglobe.com/ http://2012.inspireconf.com/ http://forefathersgroup.com/ http://www.thesearethings.com/
12
Saturday, November 10, 12
Detecting A Mobile Device 13
Saturday, November 10, 12
Detecting A Mobile Device
Nearly All Mobile Device Detection Algorithms Rely on the User Agent
13
Saturday, November 10, 12
Detecting A Mobile Device
Nearly All Mobile Device Detection Algorithms Rely on the User Agent
The User Agent is a String Sent With Your Browser’s HTTP Request
13
Saturday, November 10, 12
Detecting A Mobile Device
Nearly All Mobile Device Detection Algorithms Rely on the User Agent
The User Agent is a String Sent With Your Browser’s HTTP Request Information in the User Agent Identifies the Device, Browser, Version
Numbers, etc.
13
Saturday, November 10, 12
Detecting A Mobile Device
Nearly All Mobile Device Detection Algorithms Rely on the User Agent
The User Agent is a String Sent With Your Browser’s HTTP Request Information in the User Agent Identifies the Device, Browser, Version
Numbers, etc. There are businesses which provide a service to map User Agents to
devices
13
Saturday, November 10, 12
Detecting A Mobile Device
Nearly All Mobile Device Detection Algorithms Rely on the User Agent
The User Agent is a String Sent With Your Browser’s HTTP Request Information in the User Agent Identifies the Device, Browser, Version
Numbers, etc. There are businesses which provide a service to map User Agents to
devices They cost anywhere from $40 to $400 a month and more
13
Saturday, November 10, 12
Detecting A Mobile Device
Nearly All Mobile Device Detection Algorithms Rely on the User Agent
The User Agent is a String Sent With Your Browser’s HTTP Request Information in the User Agent Identifies the Device, Browser, Version
Numbers, etc. There are businesses which provide a service to map User Agents to
devices They cost anywhere from $40 to $400 a month and more Luckily We Have a Free Way...
13
Saturday, November 10, 12
Detecting A Mobile Device 14
Saturday, November 10, 12
Detecting A Mobile Device
A website named: Detect Mobile Browsers
14
Saturday, November 10, 12
Detecting A Mobile Device
A website named: Detect Mobile Browsers It Use Regular Expressions to Detect a Mobile Device
14
Saturday, November 10, 12
Detecting A Mobile Device
A website named: Detect Mobile Browsers It Use Regular Expressions to Detect a Mobile Device It Provides Versions of Its Algorithm for: Apache, ASP, ASP.NET,
ColdFusion, C#, IIS, JSP, JavaScript, Lasso, nginx, node.js, and more
14
Saturday, November 10, 12
Detecting A Mobile Device
A website named: Detect Mobile Browsers It Use Regular Expressions to Detect a Mobile Device It Provides Versions of Its Algorithm for: Apache, ASP, ASP.NET,
ColdFusion, C#, IIS, JSP, JavaScript, Lasso, nginx, node.js, and more The Algorithm gets Updated Every Few Months
14
Saturday, November 10, 12
Let's Get Dirty! 15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies Add Detection Code
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies Add Detection Code Test It
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies Add Detection Code Test It Add Mobile ViewPort and Meta-tags
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies Add Detection Code Test It Add Mobile ViewPort and Meta-tags Add jQuery Mobile Files
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies Add Detection Code Test It Add Mobile ViewPort and Meta-tags Add jQuery Mobile Files Convert Our Index Page
15
Saturday, November 10, 12
Let's Get Dirty!
jQuery At A Glance Make Copies Add Detection Code Test It Add Mobile ViewPort and Meta-tags Add jQuery Mobile Files Convert Our Index Page Convert Our Create Page
15
Saturday, November 10, 12
jQuery Mobile At A Glance 16
Saturday, November 10, 12
jQuery Mobile At A Glance
jQuery Uses Attributes to Enhance Markup
16
Saturday, November 10, 12
jQuery Mobile At A Glance
jQuery Uses Attributes to Enhance Markup One of the Most Import Attributes is data-role
16
Saturday, November 10, 12
jQuery Mobile At A Glance
jQuery Uses Attributes to Enhance Markup One of the Most Import Attributes is data-role By default jQuery Mobile Will Use Ajax Not Page Load
16
Saturday, November 10, 12
jQuery Mobile At A Glance
jQuery Uses Attributes to Enhance Markup One of the Most Import Attributes is data-role By default jQuery Mobile Will Use Ajax Not Page Load HTML list are Special in jQuery With Lots of Features
16
Saturday, November 10, 12
jQuery Mobile At A Glance
jQuery Uses Attributes to Enhance Markup One of the Most Import Attributes is data-role By default jQuery Mobile Will Use Ajax Not Page Load HTML list are Special in jQuery With Lots of Features jQuery Mobile is Very Semantic
16
Saturday, November 10, 12
Let’s Get Dirty!
17
Saturday, November 10, 12
Make Copies 18
Saturday, November 10, 12
Make Copies
Copy the HomeController to MobileController
18
Saturday, November 10, 12
Make Copies
Copy the HomeController to MobileController Copy _LayoutPage to _MobileLayoutPage
18
Saturday, November 10, 12
Make Copies
Copy the HomeController to MobileController Copy _LayoutPage to _MobileLayoutPage Copy the Views
18
Saturday, November 10, 12
Add Detection Code 19
Saturday, November 10, 12
Add Detection Code
Create a Named Common
19
Saturday, November 10, 12
Add Detection Code
Create a Named Common Create a Class Named DetectMobileBrowser.cs
19
Saturday, November 10, 12
Add Detection Code
Create a Named Common Create a Class Named DetectMobileBrowser.cs Create a static Method, IsMobile, With the Following Signature:
19
Saturday, November 10, 12
Add Detection Code
Create a Named Common Create a Class Named DetectMobileBrowser.cs Create a static Method, IsMobile, With the Following Signature: public static bool IsMobile(string u)
19
Saturday, November 10, 12
Add Detection Code
Create a Named Common Create a Class Named DetectMobileBrowser.cs Create a static Method, IsMobile, With the Following Signature: public static bool IsMobile(string u) Add Call to IsMobile() to the Index Action of the HomeController
19
Saturday, November 10, 12
Add Detection Code
Create a Named Common Create a Class Named DetectMobileBrowser.cs Create a static Method, IsMobile, With the Following Signature: public static bool IsMobile(string u) Add Call to IsMobile() to the Index Action of the HomeController If Detected, Redirect to the Index Action of the MobileController
19
Saturday, November 10, 12
Test It 20
Saturday, November 10, 12
Test It
Our Website Should Now Be Able To Detect Mobile Traffic
20
Saturday, November 10, 12
Test It
Our Website Should Now Be Able To Detect Mobile Traffic Let’s Test It
20
Saturday, November 10, 12
Test It
Our Website Should Now Be Able To Detect Mobile Traffic Let’s Test It We Will Use the Chrome Browser With the Ultimate User Agent
Switcher
20
Saturday, November 10, 12
Test It
Our Website Should Now Be Able To Detect Mobile Traffic Let’s Test It We Will Use the Chrome Browser With the Ultimate User Agent
Switcher Launch the Website, It Should Go To the Home page
20
Saturday, November 10, 12
Test It
Our Website Should Now Be Able To Detect Mobile Traffic Let’s Test It We Will Use the Chrome Browser With the Ultimate User Agent
Switcher Launch the Website, It Should Go To the Home page Turn on the Ultimate User Agent Switcher
20
Saturday, November 10, 12
Test It
Our Website Should Now Be Able To Detect Mobile Traffic Let’s Test It We Will Use the Chrome Browser With the Ultimate User Agent
Switcher Launch the Website, It Should Go To the Home page Turn on the Ultimate User Agent Switcher Reload the Website, We Should Go to the Mobile Home page
20
Saturday, November 10, 12
Add Mobile ViewPort and Meta-tags 21
Saturday, November 10, 12
Add Mobile ViewPort and Meta-tags
Open Up the file _MobileLayoutPage.cshtml
21
Saturday, November 10, 12
Add Mobile ViewPort and Meta-tags
Open Up the file _MobileLayoutPage.cshtml Add the meta-tags
21
Saturday, November 10, 12
Add Mobile ViewPort and Meta-tags
Open Up the file _MobileLayoutPage.cshtml Add the meta-tags viewport, width=device-width
21
Saturday, November 10, 12
Add Mobile ViewPort and Meta-tags
Open Up the file _MobileLayoutPage.cshtml Add the meta-tags viewport, width=device-width name=”apple-mobile-web-app-capable”, content=”yes”
21
Saturday, November 10, 12
Add jQuery Mobile Files 22
Saturday, November 10, 12
Add jQuery Mobile Files
Add the CSS Files
22
Saturday, November 10, 12
Add jQuery Mobile Files
Add the CSS Files Add the Script Files
22
Saturday, November 10, 12
Convert Our Index Page 23
Saturday, November 10, 12
Convert Our Index Page
Convert the <table> into a <ul>
23
Saturday, November 10, 12
Convert Our Index Page
Convert the <table> into a <ul> The data-role=”listview” Comes With Built In Styling
23
Saturday, November 10, 12
Convert Our Index Page
Convert the <table> into a <ul> The data-role=”listview” Comes With Built In Styling Remove unnecessary elements
23
Saturday, November 10, 12
Convert Our Create Page 24
Saturday, November 10, 12
Convert Our Create Page
Use Hints Instead of Labels
24
Saturday, November 10, 12
Convert Our Create Page
Use Hints Instead of Labels Use JQM Buttons
24
Saturday, November 10, 12
Convert Our Create Page
Use Hints Instead of Labels Use JQM Buttons Theme It
24
Saturday, November 10, 12
Next Steps 25
Saturday, November 10, 12
Next Steps
Convert the Remaining Views
25
Saturday, November 10, 12
Next Steps
Convert the Remaining Views Replace HTML Pages With Ajax
25
Saturday, November 10, 12
Next Steps
Convert the Remaining Views Replace HTML Pages With Ajax Make the Site iOS Friendly
25
Saturday, November 10, 12
Next Steps
Convert the Remaining Views Replace HTML Pages With Ajax Make the Site iOS Friendly
Add Home Page Icons (Android Supports These Too)
25
Saturday, November 10, 12
Next Steps
Convert the Remaining Views Replace HTML Pages With Ajax Make the Site iOS Friendly
Add Home Page Icons (Android Supports These Too) Add Splash Page
25
Saturday, November 10, 12
My Blog
http://therockncoder.blogspot.com/
26
Saturday, November 10, 12
Please Rate My Talk
http://spkr8.com/t/18331
27
Saturday, November 10, 12
Summary
Why Mobile Web? Why jQuery Mobile? 4 Ways to Add Mobile to Your Site Detecting A Mobile Device We Got Dirty Next Steps Summary
28
Saturday, November 10, 12
Resources
jQuery Mobilehttp://jquerymobile.com/
jQuery Mobile ThemeRollerhttp://jquerymobile.com/themeroller/index.php
Detect Mobile Browsershttp://detectmobilebrowsers.com/
Ultimate User Agent Switcherhttps://chrome.google.com/webstore/detail/ultimate-user-agent-switc/ljfpjnehmoiabkefmnjegmpdddgcdnpo
Window Resizerhttps://chrome.google.com/webstore/detail/window-resizer/kkelicaakdanhinjdeammmilcgefonfh
29
Saturday, November 10, 12
Feedback
Saturday, November 10, 12