Today Icelab Learned

Using viewloader with turbolinks

When using viewloader with turbolinks, you want to make sure that viewloader executes once on the initial page load, once when the visitor reaches another page, and once when the visitor goes back in their browser (or forward for that matter).

To achieve this, get viewloader to execute on the ready, page:load and page:restore events:

$(document).on("ready page:load page:restore", function() {

page:restore is fired by turbolinks whenever “A cached body element has been loaded into the DOM”.