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

Single Page Applications in Liferay

Single Page Applications in Liferay

Even modest improvements in latency can have measurable impact on a website usage. As such, sites should have aggressive goals for both actual and user perceived latency. The most obvious metric is load time, also websites often optimize and minify resources, however, even with cached resources the browser still has to re-parse and execute the CSS and JS on every page load, it still has to lay out the HTML and redraw the UI. This slows down the actual navigation but can also add perceived slowness and often introduces a white flash. In order to improve actual and perceived latencies many sites are moving to the Single Page Application (SPA) model. These days the approach is widely employed by the likes of Facebook, Twitter, GitHub, and Flickr. These examples all feel kind of app-y. Sites with more traditional layouts can still reap the benefits. Some other folks like Medium.com is technologically a single page application but it is intended to feel like a traditional website. This talk is going to teach you how to use a hybrid rendering model in an attempt to get the best out of both worlds.

Eduardo Lundgren

October 06, 2014
Tweet

More Decks by Eduardo Lundgren

Other Decks in Technology

Transcript

  1. User Perspective 10 milliseconds can make a really good game

    into a really bad game. 10 milliseconds on an e-commerce can reduce sales. Interval User perspective 0 - 100 milliseconds Instant 100 - 300 milliseconds Perceptible delay 300 - 1000 milliseconds Task Focus, Perceptible delay 1+ second Mental context switch 10+ seconds I'll come back later
  2. 10KB of HTML 3KB of CSS 500Bytes of GIFs Hacker

    News, technically, it's fast First render in <500ms
  3. The page loads really fast, but I can't read anything

    Needs to zoom and scroll The perceived performance is actually 5+ seconds What is the problem?
  4. Actual performance GPU Acceleration RAM Usage Parsers & Lexers Layers

    & Render Trees Multi-Core Optimization Energy constrains
  5. “Performance is not just milliseconds and bytes. It's also how

    milliseconds and bytes translate to how the user perceives the app” Ilya Grigorik Developer Advocate, Google
  6. “SPA is a web site that fits on a single

    web page with the goal of providing a more fluid user experience”
  7. var xhr = new XMLHttpRequest(); xhr.onload = successFn; xhr.onerror =

    errorFn; xhr.open('GET', '/foo.html'); xhr.send(); Ajax
  8. Content is empty Link is clicked
 Request content using XHR

    Ajax http://trackingjs.com Loading... Some fancy loader appears 1 2 3
  9. var xhr = new XMLHttpRequest(); xhr.onload = successFn; xhr.onerror =

    errorFn; xhr.open('GET', '/foo.html'); xhr.send(); location.hash = '#foo'; Hijax
  10. By using History API you can manipulate the browser history,

    so you can use browser’s back & forward buttons
  11. History API history.pushState(null, '', 'page02.html') page01.html page02.html page03.html history.replaceState({ key:

    123 }, '', 'page02.html') Navigate between pages without page refresh history.state: { key: 123 }
  12. History API history.pushState(null, '', 'page02.html') page01.html page02.html page03.html history.replaceState({ key:

    123 }, '', 'page02.html') Navigate between pages without page refresh "onpopstate" ‏ history.back(); history.state: null
  13. Once you load a certain surface this content is cached

    in memory and is retrieved later on without any additional request
  14. Lifecycle subsequent navigations are handled without a full page load

    Initial Page Loaded additional content is requested via Ajaxy techniques Ajax Request Update the URL Render Page Flip Screen Finalize Request pages are bookmarkable and sharable once content is ready, flip the screen render relevant parts of the page URL Routing makes it easy to wire up route handlers for different application states UI Feedback
  15. <link rel="senna-route" href="regex:.*\.html" type="senna.Screen"> ! <body data-senna> <div id="header" data-senna-surface></div>

    <div id="body" data-senna-surface></div> <div id="footer" data-senna-surface></div> </body> Data attributes
  16. Less Bandwidth Data transfered (KB) 0 350 700 1050 1400

    Page 1 Page 2 Page 3 Page 4 Refresh SPA
  17. Low Cost USD USD 20 40 USD 40 USD 100

    $30 USD 50 Monthly broadband subscription Oxford Internet Institute