SlideShare a Scribd company logo
The Mobile Web - HTML5 on mobile devices
HTML5 User Group - Atlanta
By: Wesley Hales
@wesleyhales
Wesley Hales
• Senior Developer at Red Hat           @w
                                          esle
• W3C Member                                  yha
                                                 les
• JSR 301/329 Rep.
• HTML5 User Group Founder
• html5rocks.com, DZone Refcard, and author of
  many other articles around the web.
Mobile Web Apps Live (or DIE) by the UI
The Mobile Web - HTML5 on mobile devices
Top 5 Best Practices
          When working with HTML5
1) Use client side DBs instead of server round trips 
2) Use CSS transitions instead of JavaScript animations
(Enable hardware acceleration)
3) Boost performance with JavaScript 1.6 (no more "for
loops")
4) Use cache manifests for live sites, not just offline apps
5) HTML5 Form attributes and input styles (paceholder,
pattern, etc...)
Device & Feature Detection
Device & Feature Detection


 • MobileESP (server-side)
 • Modernizr (client-side)
 • CSS3 Media Queries
Device Detection


• Parsing the USER_AGENT
• WURFL APIs
WURFL
               Wireless Universal Resource File




• Up to date list of all mobile devices
• Available as XML file
• Wrappers for most languages
Feature Detection
 Modernizr
• <html class="js canvas canvastext
  no-geolocation rgba hsla
  multiplebgs borderimage
  borderradius boxshadow opacity
  cssanimations csscolumns
  cssgradients cssreflections
  csstransforms csstransforms3d
  csstransitions video audio
  localstorage sessionstorage
  webworkers applicationcache
  fontface">
Feature Detection
  Modernizr
• Adds classnames of available
  features to DOM

• Allows use of browser features with
  fallback options

• shiv & polyfills
Feature Detection
“Cascading” the detection:
#nice {
    background: url(background-one.png) top left repeat-x;
    background: url(background-one.png) top left repeat-x,
    url(background-two.png) bottom left repeat-x;
}

Using Modernizr:

#nice {
    background: url(background-one.png) top left repeat-x;
}
.multiplebgs #nice {
    background: url(background-one.png) top left repeat-x,
    url(background-two.png) bottom left repeat-x;
}
The Mobile Web
Mobile Platforms




Mobile Frameworks




 And many more...
Todays Focus
Mobile                   Basics

• Hardware Acceleration
• Page Transitions: Sliding, Flipping, and Rotating
• Fetching and Caching
• Network Detection
• Debugging & Profiling
Hardware Acceleration

• Page Layout
• Memory allocation (Compositing)
• Power Consumption
• Conflicts
Hardware Acceleration
         Demo
Hardware Acceleration
    Understanding Page Layout
Hardware Acceleration
    Understanding Page Layout
Hardware Acceleration
      Sliding and Staging
Hardware Acceleration
      Based on device
Hardware Acceleration
                 Compositing Visuals



• Safari Command Line Flags
• Chrome about:flags
Hardware Acceleration
                     Compositing Visuals

• Safari/WebKit Command Line Flags
$> export CA_COLOR_OPAQUE=1
$> export CA_LOG_MEMORY_USAGE=1
$> /Applications/Safari.app/Contents/MacOS/Safari
Hardware Acceleration
Compositing Visuals - WebKit CoreAnimation
Hardware Acceleration
                Compositing Visuals

• Chrome about:flags
Hardware Acceleration
                      Keep In Mind


• Don’t composite every DOM element
• When you make use of the GPU, you’re
  also using the battery

• Beware of overlapping acceleration
Fetching and Caching
       Demo
Fetching and Caching


• Pre-fetch content for smooth transitions
• Setup for offline capability
• Concurrent Ajax
Caching
                by device




 appCache     unlimited     10MB

Web Storage     5MB         5MB
Fetching and Caching

Fetching content and parsing the DOM
Fetching and Caching

Fetching content and parsing the DOM
Fetching and Caching
External page parsed via AJAX call:
Fetching and Caching
localStorage used within the AJAX call:
innerHTML()
“If the HTML text contains a <script> tag or its
equivalent, then an evil script will run. ..

                     Douglas Crockford - Javascript The Good Parts
Java only is innerHTML() bad...
 Not Mobile Web Settings

• Causes browser memory leaks
• You don’t get a reference to the element
  you just created

• Problems with some elements setting
  their innerHTML

• And it fails on iOS...
Java Mobile Web Settings
Beware of innerHTML on


• Stops working randomly
• It’s a 4 year old problem in Safari
• there are hacks to workaround
  • setTimeout(‘yuck’)
Java Mobile Web Settings
      The   Solution

 • get the xhr.responseText
 • send it to an automatically generated
   HTML5 sandbox iframe

 • pull from the iframe DOM and use
   document.adoptNode
Java Mobile Web Settings
      The   Solution
function getFrame() {
    var frame = document.getElementById("temp-frame");
    if (!frame) {
        // create frame
        frame = document.createElement("iframe");
        frame.setAttribute("id", "temp-frame");
        frame.setAttribute("name", "temp-frame");
        frame.setAttribute("seamless", "");
        frame.setAttribute("sandbox", "");
        frame.style.display = 'none';
        document.documentElement.appendChild(frame);
    }
    return frame.contentDocument;
}
Java Mobile Web Settings
      The   Solution


 var frame = getFrame();
 frame.write(responseText);
Java Mobile Web Settings
        The   Solution
document.
getElementById(elementId).
appendChild(document.adoptNode
(incomingElements));
Fetching and Caching
                       Recap

• Get all fetchable links on the parent page
• Concurrently get the external pages
• Cache pages with localStorage
• Do not use innerHTML
• Write fetched content into iframe
• Place it into parent using adoptNode()
Network Detection and Handling
            Demo
Network Detection and Handling



 • Offline access through applicationCache
 • Offline/Online events
 • Content fetching based on network speed
applicationCache
             by device




appCache   unlimited     10MB
Offline Access
           appCache Mime Mappings
web.xml
<mime-mapping>
  <extension>appcache</extension>
  <mime-type>text/cache-manifest</mime-type>
</mime-mapping>


Apache config
applicationCache
demo.appcache
applicationCache
Page usage



Updating the cache
Offline & Online events
event listeners
Offline & Online events
appCache error event
Fetching based on network speed
navigator.connection (The Network Information API)
Fetching based on network speed

WIFI (Asynchronous) Request Timeline




Edge (Synchronous) Request Timeline
#atlhtml5




                     Questions?
                         @wesleyhales
Note - All code and demos presented here will be available on October 4, 2011
    www.html5rocks.com/en/mobile/optimization-and-performance.html
Ad

Recommended

Owning Web Performance with PhantomJS 2 - Fluent 2016
Owning Web Performance with PhantomJS 2 - Fluent 2016
Wesley Hales
 
Owning Web Performance
Owning Web Performance
Wesley Hales
 
JavaOne 2011 - Going Mobile With Java Based Technologies Today
JavaOne 2011 - Going Mobile With Java Based Technologies Today
Wesley Hales
 
Asset Redux - Front end performance on Rails (Phil Nash)
Asset Redux - Front end performance on Rails (Phil Nash)
Future Insights
 
JavaScript front end performance optimizations
JavaScript front end performance optimizations
Chris Love
 
A New Vue for Web Development
A New Vue for Web Development
Chad Campbell
 
Develop a vanilla.js spa you and your customers will love
Develop a vanilla.js spa you and your customers will love
Chris Love
 
Write Powerful Javascript Modules To Make Your Apps DRY (Brian Leathem)
Write Powerful Javascript Modules To Make Your Apps DRY (Brian Leathem)
Red Hat Developers
 
Prioritize your critical css and images to render your site fast velocity ny...
Prioritize your critical css and images to render your site fast velocity ny...
Jan-Willem Maessen
 
Advanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms tools
Chris Love
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
Chris Love
 
Server rendering-talk
Server rendering-talk
Daiwei Lu
 
Breaking the Speed Limit: Faster Websites Win
Breaking the Speed Limit: Faster Websites Win
Jonathan Hochman
 
More efficient, usable web
More efficient, usable web
Chris Mills
 
Building Modern Web Apps with MEAN Stack
Building Modern Web Apps with MEAN Stack
Suresh Patidar
 
Javascript for Wep Apps
Javascript for Wep Apps
Michael Puckett
 
Vue - the Progressive Framework
Vue - the Progressive Framework
myposter GmbH
 
Intro to Vue
Intro to Vue
Isatu Conteh
 
Drupal8 + AngularJS
Drupal8 + AngularJS
Daniel Kanchev
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
Jeremy Likness
 
Building Angular Component Libraries
Building Angular Component Libraries
Isatu Conteh
 
The MEAN Stack
The MEAN Stack
Md. Ziaul Haq
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
Mayank Srivastava
 
MEAN stack
MEAN stack
Iryney Baran
 
Using Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the Web
philogb
 
Get MEAN! Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
ReactJS - Re-rendering pages in the age of the mutable DOM
ReactJS - Re-rendering pages in the age of the mutable DOM
Marc Cyr
 
MongoDB and the MEAN Stack
MongoDB and the MEAN Stack
MongoDB
 
Web app and more
Web app and more
faming su
 
Web Apps and more
Web Apps and more
Yan Shi
 

More Related Content

What's hot (20)

Prioritize your critical css and images to render your site fast velocity ny...
Prioritize your critical css and images to render your site fast velocity ny...
Jan-Willem Maessen
 
Advanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms tools
Chris Love
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
Chris Love
 
Server rendering-talk
Server rendering-talk
Daiwei Lu
 
Breaking the Speed Limit: Faster Websites Win
Breaking the Speed Limit: Faster Websites Win
Jonathan Hochman
 
More efficient, usable web
More efficient, usable web
Chris Mills
 
Building Modern Web Apps with MEAN Stack
Building Modern Web Apps with MEAN Stack
Suresh Patidar
 
Javascript for Wep Apps
Javascript for Wep Apps
Michael Puckett
 
Vue - the Progressive Framework
Vue - the Progressive Framework
myposter GmbH
 
Intro to Vue
Intro to Vue
Isatu Conteh
 
Drupal8 + AngularJS
Drupal8 + AngularJS
Daniel Kanchev
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
Jeremy Likness
 
Building Angular Component Libraries
Building Angular Component Libraries
Isatu Conteh
 
The MEAN Stack
The MEAN Stack
Md. Ziaul Haq
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVC
Mayank Srivastava
 
MEAN stack
MEAN stack
Iryney Baran
 
Using Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the Web
philogb
 
Get MEAN! Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
ReactJS - Re-rendering pages in the age of the mutable DOM
ReactJS - Re-rendering pages in the age of the mutable DOM
Marc Cyr
 
MongoDB and the MEAN Stack
MongoDB and the MEAN Stack
MongoDB
 
Prioritize your critical css and images to render your site fast velocity ny...
Prioritize your critical css and images to render your site fast velocity ny...
Jan-Willem Maessen
 
Advanced front end debugging with ms edge and ms tools
Advanced front end debugging with ms edge and ms tools
Chris Love
 
Disrupting the application eco system with progressive web applications
Disrupting the application eco system with progressive web applications
Chris Love
 
Server rendering-talk
Server rendering-talk
Daiwei Lu
 
Breaking the Speed Limit: Faster Websites Win
Breaking the Speed Limit: Faster Websites Win
Jonathan Hochman
 
More efficient, usable web
More efficient, usable web
Chris Mills
 
Building Modern Web Apps with MEAN Stack
Building Modern Web Apps with MEAN Stack
Suresh Patidar
 
Vue - the Progressive Framework
Vue - the Progressive Framework
myposter GmbH
 
Single Page Applications: Your Browser is the OS!
Single Page Applications: Your Browser is the OS!
Jeremy Likness
 
Building Angular Component Libraries
Building Angular Component Libraries
Isatu Conteh
 
Using Web Standards to create Interactive Data Visualizations for the Web
Using Web Standards to create Interactive Data Visualizations for the Web
philogb
 
Get MEAN! Node.js and the MEAN stack
Get MEAN! Node.js and the MEAN stack
Nicholas McClay
 
ReactJS - Re-rendering pages in the age of the mutable DOM
ReactJS - Re-rendering pages in the age of the mutable DOM
Marc Cyr
 
MongoDB and the MEAN Stack
MongoDB and the MEAN Stack
MongoDB
 

Similar to The Mobile Web - HTML5 on mobile devices (20)

Web app and more
Web app and more
faming su
 
Web Apps and more
Web Apps and more
Yan Shi
 
HTML5 on Mobile
HTML5 on Mobile
Adam Lu
 
HTML5와 모바일
HTML5와 모바일
ACCESS
 
Html5
Html5
Zahin Omar Alwa
 
Pablo Villalba -
Pablo Villalba -
.toster
 
Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)
Adam Lu
 
Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app
Ivano Malavolta
 
Performance Optimization for Mobile Web | Fresh Tilled Soil
Performance Optimization for Mobile Web | Fresh Tilled Soil
Fresh Tilled Soil
 
Mobile Web Development with HTML5
Mobile Web Development with HTML5
Roy Clarkson
 
The Mobile Web Revealed For The Java Developer
The Mobile Web Revealed For The Java Developer
balunasj
 
Cross platform mobile web apps
Cross platform mobile web apps
James Pearce
 
Extreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NY
Maximiliano Firtman
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
James Pearce
 
Extreme Web Performance for Mobile Device Fluent 2015
Extreme Web Performance for Mobile Device Fluent 2015
Maximiliano Firtman
 
Mobile App Development
Mobile App Development
Chris Morrell
 
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Maximiliano Firtman
 
HTML5 Technical Executive Summary
HTML5 Technical Executive Summary
Gilad Khen
 
HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)
Andi Farr
 
High Performance Mobile Web
High Performance Mobile Web
Morgan Cheng
 
Web app and more
Web app and more
faming su
 
Web Apps and more
Web Apps and more
Yan Shi
 
HTML5 on Mobile
HTML5 on Mobile
Adam Lu
 
Pablo Villalba -
Pablo Villalba -
.toster
 
Html5 on Mobile(For Developer)
Html5 on Mobile(For Developer)
Adam Lu
 
Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app
Ivano Malavolta
 
Performance Optimization for Mobile Web | Fresh Tilled Soil
Performance Optimization for Mobile Web | Fresh Tilled Soil
Fresh Tilled Soil
 
Mobile Web Development with HTML5
Mobile Web Development with HTML5
Roy Clarkson
 
The Mobile Web Revealed For The Java Developer
The Mobile Web Revealed For The Java Developer
balunasj
 
Cross platform mobile web apps
Cross platform mobile web apps
James Pearce
 
Extreme Web Performance for Mobile Devices - Velocity NY
Extreme Web Performance for Mobile Devices - Velocity NY
Maximiliano Firtman
 
HTML5 and the dawn of rich mobile web applications pt 1
HTML5 and the dawn of rich mobile web applications pt 1
James Pearce
 
Extreme Web Performance for Mobile Device Fluent 2015
Extreme Web Performance for Mobile Device Fluent 2015
Maximiliano Firtman
 
Mobile App Development
Mobile App Development
Chris Morrell
 
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Extreme Web Performance for Mobile Devices - Velocity Barcelona 2014
Maximiliano Firtman
 
HTML5 Technical Executive Summary
HTML5 Technical Executive Summary
Gilad Khen
 
HTML5 apps for iOS (and probably beyond)
HTML5 apps for iOS (and probably beyond)
Andi Farr
 
High Performance Mobile Web
High Performance Mobile Web
Morgan Cheng
 
Ad

More from Wesley Hales (6)

Making Portals Cool: The Compelling Advantages of a Portlet Bridge
Making Portals Cool: The Compelling Advantages of a Portlet Bridge
Wesley Hales
 
Filling The Gap - Going Mobile With JBoss Technologies Today
Filling The Gap - Going Mobile With JBoss Technologies Today
Wesley Hales
 
If You Know JSF, You Know Portals and Portlets
If You Know JSF, You Know Portals and Portlets
Wesley Hales
 
GateIn - The Solution for Managing and Building Enterprise Web Apps
GateIn - The Solution for Managing and Building Enterprise Web Apps
Wesley Hales
 
GateIn - Presented at Atlanta JUG on 1/19/2010
GateIn - Presented at Atlanta JUG on 1/19/2010
Wesley Hales
 
Ajax In Enterprise Portals
Ajax In Enterprise Portals
Wesley Hales
 
Making Portals Cool: The Compelling Advantages of a Portlet Bridge
Making Portals Cool: The Compelling Advantages of a Portlet Bridge
Wesley Hales
 
Filling The Gap - Going Mobile With JBoss Technologies Today
Filling The Gap - Going Mobile With JBoss Technologies Today
Wesley Hales
 
If You Know JSF, You Know Portals and Portlets
If You Know JSF, You Know Portals and Portlets
Wesley Hales
 
GateIn - The Solution for Managing and Building Enterprise Web Apps
GateIn - The Solution for Managing and Building Enterprise Web Apps
Wesley Hales
 
GateIn - Presented at Atlanta JUG on 1/19/2010
GateIn - Presented at Atlanta JUG on 1/19/2010
Wesley Hales
 
Ajax In Enterprise Portals
Ajax In Enterprise Portals
Wesley Hales
 
Ad

Recently uploaded (20)

The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Oh, the Possibilities - Balancing Innovation and Risk with Generative AI.pdf
Priyanka Aash
 
Mastering AI Workflows with FME by Mark Döring
Mastering AI Workflows with FME by Mark Döring
Safe Software
 
UserCon Belgium: Honey, VMware increased my bill
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
You are not excused! How to avoid security blind spots on the way to production
You are not excused! How to avoid security blind spots on the way to production
Michele Leroux Bustamante
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
" How to survive with 1 billion vectors and not sell a kidney: our low-cost c...
Fwdays
 
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Cracking the Code - Unveiling Synergies Between Open Source Security and AI.pdf
Priyanka Aash
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
AI VIDEO MAGAZINE - June 2025 - r/aivideo
AI VIDEO MAGAZINE - June 2025 - r/aivideo
1pcity Studios, Inc
 
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Using the SQLExecutor for Data Quality Management: aka One man's love for the...
Safe Software
 
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
A Constitutional Quagmire - Ethical Minefields of AI, Cyber, and Privacy.pdf
Priyanka Aash
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
 

The Mobile Web - HTML5 on mobile devices

  • 1. The Mobile Web - HTML5 on mobile devices HTML5 User Group - Atlanta By: Wesley Hales @wesleyhales
  • 2. Wesley Hales • Senior Developer at Red Hat @w esle • W3C Member yha les • JSR 301/329 Rep. • HTML5 User Group Founder • html5rocks.com, DZone Refcard, and author of many other articles around the web.
  • 3. Mobile Web Apps Live (or DIE) by the UI
  • 5. Top 5 Best Practices When working with HTML5 1) Use client side DBs instead of server round trips  2) Use CSS transitions instead of JavaScript animations (Enable hardware acceleration) 3) Boost performance with JavaScript 1.6 (no more "for loops") 4) Use cache manifests for live sites, not just offline apps 5) HTML5 Form attributes and input styles (paceholder, pattern, etc...)
  • 6. Device & Feature Detection
  • 7. Device & Feature Detection • MobileESP (server-side) • Modernizr (client-side) • CSS3 Media Queries
  • 8. Device Detection • Parsing the USER_AGENT • WURFL APIs
  • 9. WURFL Wireless Universal Resource File • Up to date list of all mobile devices • Available as XML file • Wrappers for most languages
  • 10. Feature Detection Modernizr • <html class="js canvas canvastext no-geolocation rgba hsla multiplebgs borderimage borderradius boxshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions video audio localstorage sessionstorage webworkers applicationcache fontface">
  • 11. Feature Detection Modernizr • Adds classnames of available features to DOM • Allows use of browser features with fallback options • shiv & polyfills
  • 12. Feature Detection “Cascading” the detection: #nice {     background: url(background-one.png) top left repeat-x;     background: url(background-one.png) top left repeat-x,     url(background-two.png) bottom left repeat-x; } Using Modernizr: #nice {     background: url(background-one.png) top left repeat-x; } .multiplebgs #nice {     background: url(background-one.png) top left repeat-x,     url(background-two.png) bottom left repeat-x; }
  • 16. Mobile Basics • Hardware Acceleration • Page Transitions: Sliding, Flipping, and Rotating • Fetching and Caching • Network Detection • Debugging & Profiling
  • 17. Hardware Acceleration • Page Layout • Memory allocation (Compositing) • Power Consumption • Conflicts
  • 19. Hardware Acceleration Understanding Page Layout
  • 20. Hardware Acceleration Understanding Page Layout
  • 21. Hardware Acceleration Sliding and Staging
  • 22. Hardware Acceleration Based on device
  • 23. Hardware Acceleration Compositing Visuals • Safari Command Line Flags • Chrome about:flags
  • 24. Hardware Acceleration Compositing Visuals • Safari/WebKit Command Line Flags $> export CA_COLOR_OPAQUE=1 $> export CA_LOG_MEMORY_USAGE=1 $> /Applications/Safari.app/Contents/MacOS/Safari
  • 26. Hardware Acceleration Compositing Visuals • Chrome about:flags
  • 27. Hardware Acceleration Keep In Mind • Don’t composite every DOM element • When you make use of the GPU, you’re also using the battery • Beware of overlapping acceleration
  • 29. Fetching and Caching • Pre-fetch content for smooth transitions • Setup for offline capability • Concurrent Ajax
  • 30. Caching by device appCache unlimited 10MB Web Storage 5MB 5MB
  • 31. Fetching and Caching Fetching content and parsing the DOM
  • 32. Fetching and Caching Fetching content and parsing the DOM
  • 33. Fetching and Caching External page parsed via AJAX call:
  • 34. Fetching and Caching localStorage used within the AJAX call:
  • 36. “If the HTML text contains a <script> tag or its equivalent, then an evil script will run. .. Douglas Crockford - Javascript The Good Parts
  • 37. Java only is innerHTML() bad... Not Mobile Web Settings • Causes browser memory leaks • You don’t get a reference to the element you just created • Problems with some elements setting their innerHTML • And it fails on iOS...
  • 38. Java Mobile Web Settings Beware of innerHTML on • Stops working randomly • It’s a 4 year old problem in Safari • there are hacks to workaround • setTimeout(‘yuck’)
  • 39. Java Mobile Web Settings The Solution • get the xhr.responseText • send it to an automatically generated HTML5 sandbox iframe • pull from the iframe DOM and use document.adoptNode
  • 40. Java Mobile Web Settings The Solution function getFrame() {     var frame = document.getElementById("temp-frame");     if (!frame) {         // create frame         frame = document.createElement("iframe");         frame.setAttribute("id", "temp-frame");         frame.setAttribute("name", "temp-frame");         frame.setAttribute("seamless", "");         frame.setAttribute("sandbox", "");         frame.style.display = 'none';         document.documentElement.appendChild(frame);     }     return frame.contentDocument; }
  • 41. Java Mobile Web Settings The Solution var frame = getFrame(); frame.write(responseText);
  • 42. Java Mobile Web Settings The Solution document. getElementById(elementId). appendChild(document.adoptNode (incomingElements));
  • 43. Fetching and Caching Recap • Get all fetchable links on the parent page • Concurrently get the external pages • Cache pages with localStorage • Do not use innerHTML • Write fetched content into iframe • Place it into parent using adoptNode()
  • 44. Network Detection and Handling Demo
  • 45. Network Detection and Handling • Offline access through applicationCache • Offline/Online events • Content fetching based on network speed
  • 46. applicationCache by device appCache unlimited 10MB
  • 47. Offline Access appCache Mime Mappings web.xml <mime-mapping> <extension>appcache</extension> <mime-type>text/cache-manifest</mime-type> </mime-mapping> Apache config
  • 50. Offline & Online events event listeners
  • 51. Offline & Online events appCache error event
  • 52. Fetching based on network speed navigator.connection (The Network Information API)
  • 53. Fetching based on network speed WIFI (Asynchronous) Request Timeline Edge (Synchronous) Request Timeline
  • 54. #atlhtml5 Questions? @wesleyhales Note - All code and demos presented here will be available on October 4, 2011 www.html5rocks.com/en/mobile/optimization-and-performance.html