Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Speeding Up your Mobile HTML5 Experience

firtman
June 18, 2013

Speeding Up your Mobile HTML5 Experience

Slides from the tutorial at Velocity Conference Santa Clara 2013

firtman

June 18, 2013
Tweet

Other Decks in Technology

Transcript

  1. speeding up your mobile html5 experience max firtman @firt firt.mobi

    June, 18, 2013 Santa Clara, CA Tuesday, June 18, 13
  2. performance + mobile + html5 1- Mobile & Performance 2-

    Measuring 3- e worst - with examples! :) 4- What to do... always 5- What to do... sometimes Tuesday, June 18, 13
  3. 1- mobile & performance - e ecosystem in 2013 -

    HTML5 - What performance means - Differences Tuesday, June 18, 13
  4. Browser to install Full-screen Icon on home screen Web Server

    2- webapps we can create Tuesday, June 18, 13
  5. Package, compile, sign Icon on home screen App Store No

    web server 3- native webapps we can create Tuesday, June 18, 13
  6. load 3s ok, I'm still there feedback 1s ok, I'm

    still there perception Tuesday, June 18, 13
  7. Latency (ms) cellular networks 2G 300 - 1000 3G 150

    - 450 4G 100 - 180 Tuesday, June 18, 13
  8. Latency (ms) cellular networks 2G 300 - 1000 3G 4G

    150 - 450 100 - 180 Home wired connections in US: 20-45 Tuesday, June 18, 13
  9. From Idle to Active cellular networks 3G < 2.5 s

    4G < 100 ms Tuesday, June 18, 13
  10. 1- mobile & performance - Complex will change - not

    just websites - not just load time - cellular networks Tuesday, June 18, 13
  11. 2- measuring on mobile - the target - tools -

    HTML5 APIs Tuesday, June 18, 13
  12. Remote inspectors • BlackBerry Smartphones 7/10 • Google Chrome for

    Android • Opera Mobile • Safari on iOS 6+ • Firefox (Android / FFOS) tools Tuesday, June 18, 13
  13. Navigation Timing API • Android 4.0+, Chrome, BB10, IE9+, Firefox

    • window.performance • Timestamps available html5 apis Tuesday, June 18, 13
  14. Network Information API • Old spec: navigator.connection.type Android Browser /

    Apache Cordova • New spec: navigator.connection.bandwidth BlackBerry 10 / Firefox html5 apis Tuesday, June 18, 13
  15. 2- measuring on mobile - measure on real devices only

    - tools: remote debuggers, proxies - HTML5 APIs Tuesday, June 18, 13
  16. 3- the worst - redirects - requests - design &

    usability - javascript - responsive web design? Tuesday, June 18, 13
  17. Redirects • From 150 to 1000 ms per redirect •

    mydomain.com -> m.mydomain.com • URL shorteners • It can be worst! the worst Tuesday, June 18, 13
  18. Redirections the worst aa.com -> www.aa.com -> www.aa.com/homePage.do -> mobile.aa.com

    -> www.aa.com/mt -> www.aa.com/mt/homePage.do Tuesday, June 18, 13
  19. Requests • Best -> no requests • Remember latency and

    idle status • Keep them to the minimum, really! the worst Tuesday, June 18, 13
  20. Usability and Design • Be mobile • Careful with blending

    • Test and measure • e designer is a better enemy the worst Tuesday, June 18, 13
  21. JavaScript • Really expensive • Blocks downloads and responsiveness •

    Repaint and DOM manipulation, the worst • Too frequent timers? mmmm • Frameworks... oh, frameworks.... the worst Tuesday, June 18, 13
  22. Responsive Web Design the worst Oh, do we need to

    talk about this? Tuesday, June 18, 13
  23. Brad Frost "Your visitors don’t give a shit if your

    site is responsive." the worst Tuesday, June 18, 13
  24. Responsive Web Design • Don't use it just because it's

    cool • RWD is great on some situations • RWD is terrible on other situations • Add some server-side logic -> RESS the worst Tuesday, June 18, 13
  25. 3- the worst - don't redirect, don't stop your user

    - avoid requests at all cost - balance design, get a new enemy - keep javascript at the minimum - responsive web design? Tuesday, June 18, 13
  26. 4- what to do always - remembering last chapter -

    javascript frameworks - classic techniques - improve speed Tuesday, June 18, 13
  27. Remembering... • don´t redirect • keep your requests to the

    minimum • cool not always goes with performance what to do always Tuesday, June 18, 13
  28. JavaScript frameworks • do you need them?, really? • customize

    your build to your needs • use alternatives what to do always Tuesday, June 18, 13
  29. Classic techniques • Enable GZIP for text-based les • Compress

    CSS & JS • Only the CSS and JS you are using • reduce DNS lookup • stylesheets at the top what to do always Tuesday, June 18, 13
  30. Classic techniques • script at the bottom, or better: *

    async loading * use html5 new attributes what to do always <script async defer src=""></script> HTML5 Tuesday, June 18, 13
  31. Reduce the DOM • Keep it really simple • For

    in nite scrolling • Use object pools • Use iframes what to do always Tuesday, June 18, 13
  32. Improve perception • Flush early, be ready asap • If

    you have an external CSS, ush aer it • Hide URL bar asap • Pre-fetch and batch requests on progressive loading what to do always Tuesday, June 18, 13
  33. Improve perception • mouse vs touch events • e 300ms

    delay • xed viewport? • FastClick solution what to do always Tuesday, June 18, 13
  34. 4- what to do always - follow classic techniques, use

    desktop tools - create a perception of speed - measure, test, measure test Tuesday, June 18, 13
  35. Most of the solutions and best practices are not for

    every kind of html5 project ( ) Tuesday, June 18, 13
  36. 5- what to do sometimes - improve the experience -

    server communication - javascript - media - responsive images Tuesday, June 18, 13
  37. Improve experience what to do sometimes use Application Cache •

    perception of immediate loading • only for html and basic resources • updating is still a problem • buggy Tuesday, June 18, 13
  38. Improve experience what to do sometimes HD / SD version

    • make a decision based on the context • allow the user to switch to a light version • copy YouTube idea Tuesday, June 18, 13
  39. Network communication what to do sometimes Server-side events • keep

    an HTTP request opened • re-connects automatically • send contents in batch (in JSON/XML) Tuesday, June 18, 13
  40. Network communication what to do sometimes Web Sockets • less

    overhead • bidirectional • use with care: battery, reliability Tuesday, June 18, 13
  41. Network communication what to do sometimes Data URI • embrace

    embedded content • use it with storage APIs for caching • much better than a request Tuesday, June 18, 13
  42. Network communication what to do sometimes Custom Cache • Up

    to 5x faster than standard browser cache • Cookies for server-side detection or a light JS detection framework • Up to 2.5Mb safe (4Mb using compression) Tuesday, June 18, 13
  43. Custom cache browser server request (no cookies) response full html

    inline images css styles javascript code stores resources in localStorage and create cookie Tuesday, June 18, 13
  44. Custom cache first load browser server request (no cookies) response

    full html inline images css styles javascript code stores resources in localStorage and create cookie Tuesday, June 18, 13
  45. Custom cache browser server request (with cookies) response basic html

    basic javascript updated resources Tuesday, June 18, 13
  46. Custom cache second load browser server request (with cookies) response

    basic html basic javascript updated resources Tuesday, June 18, 13
  47. Network communication what to do sometimes HTTP 2.0 • Near

    future • Today: SPDY; Chrome Tuesday, June 18, 13
  48. JavaScript what to do sometimes • Web Workers var w

    = new Worker("worker.js"); w.addEventListener("message", function(e) { }); w.postMessage("Hi Worker!") JAVASCRIPT Tuesday, June 18, 13
  49. Media what to do sometimes • CSS Sprites vs. inline

    elements vs. JSON Resource library Tuesday, June 18, 13
  50. Media what to do sometimes • Always use CSS transitions/animations

    when possible • On games and user-based animations, ask for Animation Timing API (requestAnimationFrame) • Use Page Visibility API to pause/resume Animations Tuesday, June 18, 13
  51. Media what to do sometimes • Using a 3D transform

    • Be careful; the GPU is also limited • Apple is not recommending this hack anymore Hardware acceleration Tuesday, June 18, 13
  52. Media what to do sometimes • Progressive JPEGs • WebP

    • JPEG XR Alternative image formats Tuesday, June 18, 13
  53. Media what to do sometimes • Blocks rendering -> performance

    issue • Remove characters from the font le • Use a web font loader • Fonts in Data URI on some platforms Custom fonts Tuesday, June 18, 13
  54. Screen densities 300 CSS pixels 300 1.00 390 1.30 450

    1.50 600 2.00 672 2.24 900 3.00 device px px ratio what to do sometimes Tuesday, June 18, 13
  55. Screen densities using javascript if (window.devicePixelRatio > 1.5) { //

    change URL } what to do sometimes Tuesday, June 18, 13
  56. Screen densities using css extensions #photoContainer { background-image: -webkit-image-set(url('photo-lo.png') 1x,

    url('photo-hi.png') 2x); width: 300px; height: 200px; } what to do sometimes Tuesday, June 18, 13
  57. Screen densities using css media queries @media (-webkit-min-device-pixel-ratio: 1.5), (min--moz-device-pixel-ratio:

    1.5), (-o-min-device-pixel-ratio: 3/2), (min-resolution: 1.5dppx) { } what to do sometimes Tuesday, June 18, 13
  58. Screen densities • transfer, decoding time and memory usage •

    try and measure • For 1x, always image of 1x • For 2x: image of 2x, 1.5x? • For 3x: image of 2x? 3x?? what to do sometimes Tuesday, June 18, 13
  59. 5- what to do sometimes - improve the experience -

    server comunication - javascript - media - screen densities Tuesday, June 18, 13
  60. 1- Mobile & Performance 2- Measuring 3- e worst 4-

    What to do... always 5- What to do... sometimes Tuesday, June 18, 13
  61. performance and mobile - learn to measure - be simple,

    be aggressive - test every technique - keep measuring - change is the only constant Tuesday, June 18, 13
  62. you can reach a good experience Pictures)from)freedigitalphotos.net) thank you! firt.mobi

    twitter: @firt www.mobilexweb.com rt.mobi/pmw Tuesday, June 18, 13