Binding to turbolinks concept of a page load
suggest changeWith Turbolinks 5, this traditional hook does not run again after the first page:
$(document).ready(function() {
// awesome code
});
$(document).ready() fires only on the initial full page load. Later link clicks are intercepted. Turbolinks fetches the next page with Ajax, replaces <body>, and merges <head>. That cycle is a visit. Bind to the visit event instead of document.ready:
// plain JavaScript
document.addEventListener("turbolinks:load", function() {
// awesome code
});
// jQuery
$(document).on('turbolinks:load', function() {
// your code
});
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents