• More is better. • Array#first or Array[0]? Up to you! • alias_method everywhere! • Trivia: other platform/framework discourage duplication because it is confusing. • Ruby and Rails encourage aliasing because, well, without it, it is confusing!
it has been being stand-alone since years ago • No dependency to any Javascript framework! • Bring SPA-responsiveness to standard Rails application (Thanks toTurbolinks Preview and History Navigation) • Changing DOM • Less browser requests, less 304 Not Modified. That means faster response! • It is included in Rails. You may remove it, but you can also use it. Up to the devs.
may be sent if: • If-Modified-Since was the same with server’s version • ETag hash is the same with server’s version • But the request still happens... Even if the response’s body is 0 bytes. • Slower request!
was allowed to be previewed? Asynchronously load target href 2. TURBOLINKS VISIT Load from cache, inject ‘data-turbolinks-preview=true’ in <html /> root YES NO Assets version changed? Page loaded Do a full reload YES Replace metas, title, and body NO Put in cache (if allowed)
was allowed to be previewed? Asynchronously load target href 2. TURBOLINKS VISIT Load from cache, inject ‘data-turbolinks-preview=true’ in <html /> root YES NO Assets version changed? Page loaded Do a full reload YES Replace metas, title, and body NO Put in cache (if allowed)
was allowed to be cached? Asynchronously load target href 3. HISTORY NAVIGATION Load from cache YES NO Assets version changed? Page loaded Do a full reload YES Replace metas, title, and body NO Put in cache (if allowed)
was allowed to be cached? Asynchronously load target href 3. HISTORY NAVIGATION Load from cache YES NO Assets version changed? Page loaded Do a full reload YES Replace metas, title, and body NO Put in cache (if allowed)
only once or multiple times! • Careful: Don’t attach turbolinks:load in inline script, since it will be fired twice! • Recommended way: • Require all components in application.js • Since each page is unique; put initialization as inline script, at the end of the body – so that page specific JS won’t make main script dirty COMPONENT INITIALIZATION
in data- • Define actions in data- • Use .on, put .on inside main script that is included by application.js • If it is page specific, use inline script. EVENT INJECTION
before next Turbolinks’ visit (add cleanup via turbolinks:before-render) • Warning again: all inline scripts are executed twice with Turbolinks’ Preview!