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

A Chain Is No Stronger Than Its Weakest Turbolink

Bruno Cunha
November 21, 2016

A Chain Is No Stronger Than Its Weakest Turbolink

Turbolinks deep dive on navigation, native applications, and advanced usage

Bruno Cunha

November 21, 2016
Tweet

More Decks by Bruno Cunha

Other Decks in Technology

Transcript

  1. Turbolinks makes navigating your web application faster. Get the performance

    benefits of a single-page application without the added complexity of a client-side JavaScript framework.
  2. Respects the web. The Back and Reload buttons work just

    as you’d expect. Search engine-friendly by design.
  3. Supports mobile apps. Adapters for iOS and Android let you

    build hybrid applications using native navigation controls.
  4. Turbolinks intercepts all clicks on <a href> links to the

    same domain. When you click an eligible link, Turbolinks prevents the browser from following it, changes the browser’s URL using the History API, requests the new page using XMLHttpRequest, and then renders the HTML response.
  5. Render your views on server-side and link to pages as

    usual. When you follow a link, Turbolinks fetches the page, swaps in its <body>, and merges its <head>, all without incurring the cost of a full page load.
  6. The default visit action is advance, which pushes a new

    entry onto the browser’s history stack using history.pushState.
  7. Visit a location without pushing a new history entry onto

    the stack using the replace visit action. It uses history.replaceState to discard the topmost history entry and replace it with the new location.
  8. You can no longer depend on a full page load

    to reset your environment every time you navigate.
  9. You may be used to installing JavaScript behavior in response

    to the window.onload, DOMContentLoaded, or jQuery ready events. Adjust your code to listen for the turbolinks:load event, which fires once on the initial page load and again after every Turbolinks visit.
  10. When you navigate to a new page, Turbolinks appends any

    new <script> elements to the current <head> where they’re loaded and evaluated by the browser. Take advantage of this to install page-specific javascript.
  11. Turbolinks maintains a cache of recently visited pages. This cache

    serves two purposes: to display pages without accessing the network during restoration visits, and to improve perceived performance by showing temporary previews during application visits.
  12. Allow elements to persist between page loads by designating them

    as permanent - simply give them an HTML id and annotate them with data-turbolinks-permanent.