Save 37% off PRO during our Black Friday Sale! »

Fast Mobile UIs

Fast Mobile UIs

This slide deck is meant to support my talk about the hoops one has to jump through to make their web application's user interface (UI) responsive and up to par with native applications.

2df2fcdb4bea51567940c6beb9a34f4d?s=128

Horia Dragomir

April 23, 2012
Tweet

Transcript

  1. Fast Mobile UIs You’re an Edge Case

  2. Who am I, right? Horia Dragomir UI Developer @ wooga

    HTML5 Social Games
  3. Mobile UI != Desktop UI

  4. Mobile UI is Harder • Awesome standard support • No

    IE6 • Super hardware
  5. Forget What You Knew

  6. Learn by Doing

  7. Learn by Solving Problems

  8. We Used to Have No Debugging

  9. Thank you, Adobe and Opera!

  10. Thank you, Apple! [NSClassFromString(@"WebView") _enableRemoteInspector];

  11. Thank you, Google! Thy Chrome Robot is amazing!

  12. Viewport

  13. Viewport • It's actually hard to use the full screen

    • Use a custom hack
  14. Viewport • Viewporter tries to solve this problem, but fails

    • You webapp will run in far too many environments to create profiles for
  15. Speed

  16. iOS versus Android Android is usually half as fast*

  17. iOS versus Android Android is usually half as fast http://daringfireball.net/linked/2012/03/05/ios-android-html5-benchmarks

  18. Loading Speed • Show first, load later • Loading JS

    can freeze the UI • Lazy-loading?
  19. HTTP Hates You Roundtrips are expensive Try pipelining

  20. applicationCache is a lie • Loads in one gulp •

    Loads in order • the UI will hate this • Use it with care
  21. Golf Everything! 140byt.es

  22. Golf? • Make you application smaller and smaller and keep

    it as small as you can
  23. Be Awesome!

  24. Be Awesome?

  25. None
  26. You Don’t Need jQuery! • I <3 jQuery, but not

    on mobile.
  27. HTML5 is Awesome!

  28. USE IT!

  29. .querySelectorAll() • [].map.call • super fast!

  30. .querySelectorAll() [].map.call(node.querySelectorAll('a .super'), function (child) { //awesome stuff here });

  31. .querySelectorAll() http://snook.ca/archives/javascript/going- simple-with-javascript

  32. getElementsByClassName • blazing fast!

  33. getElementById

  34. Use Event Bubbling!

  35. Use Event Bubbling! instead of addingEventListeners to every node, just

    add one to their parent. It’s what the cool kids are doing!
  36. XMLHttpRequest rocks the boat • req.overrideMimeType('text/plain; charset=x-user-defined');

  37. req.responseCode < 400

  38. req.responseCode < 400 An AJAX request to an asset already

    stored in applicationCache will sometimes yield a responseCode of 0
  39. pushState for navigation

  40. requestAnimationFrame

  41. requestAnimationFrame • function(a,b){while(a--&&! (b=this["oR0msR0mozR0webkitR0r".split(0 )[a]+"equestAnimationFrame"]));return b|| function(a){setTimeout(a,15)}}(5) • https://gist.github.com/997619

  42. Redraws Hate You

  43. CSS is your friend

  44. Animations are hard • Think of the poor CPU •

    Use transitions! • Use CSS3 transforms
  45. Also, cheat and add dummy transforms just to get things

    HW accelerated
  46. Android hates multiple transforms You will end up having simplified

    animations for Android. That’s OK.
  47. Also, turn off Hardware Acceleration for Android 2.x Thank you,

    Ben Green!
  48. node[data-mode=”super”] • classes are cool for binary switches, though

  49. Tread with care • CSS3 does not always follow live

    DOM events
  50. Tread with care • CSS3 does not always follow live

    DOM events • See this for an example: http://jsbin.com/orolov/12/edit#html,live
  51. Small hacks go a long way

  52. onclick is broken for a good reason

  53. Roll your own “onclick” • use touchstart, touchmove and touchend

    • enable longtouch listener
  54. document.addEventListener('touchend', function () {}, false); This enables the :active selector

    and increases the perceived responsiveness of your app
  55. Perceived Responsiveness Delay JS heavy execution to allow the UI

    to respond fast.
  56. Perceived Responsiveness http://alexmaccaw.co.uk/posts/async_ui

  57. None
  58. None
  59. None
  60. format-detection telephone=no This will not always work, so you will

    need to insert dummy <span>s here and there
  61. pointer-events: none; user-select: none; user-drag: none;

  62. name=viewport content="initial-scale=0.5" • Use CSS3 transforms to scale things back

    to size • Or just use bigger graphics
  63. device-pixel-ratio

  64. Use optimized images • pngnq • spritopia • Android has

    navigator.connection
  65. Android was broken, though

  66. Boot 2 Gecko

  67. Firefox OS

  68. Firefox OS Chrome OS?!

  69. WebApps

  70. WebApps http://singlepageappbook.com/

  71. You should be an edge case this means you're doing

    something special
  72. You should be an edge case @hdragomir @wooga this means

    you're doing something special
  73. http://speakerdeck.com/u/hdragomir/p/fast-mobile-uis @hdragomir @wooga http://www.slideshare.net/wooga