onmount is a perfect fit with projects that use Turbolinks. You’ll notice that jQuery’s document
ready
event is not friendly for Turbolinks applications. You should call $.onmount()
when Turbolinks changes pages.
The event is turbolinks:load
for Turbolinks 5. You will also need to teardown behaviors on turbolinks:before-cache
(info).
$(document).on('ready turbolinks:load', function () { $.onmount() })
$(document).on('turbolinks:before-cache', function () { $.onmount.teardown() })
Discussion on this setup may be found here.
The event is page:change
For Turbolinks 2 and below.
$(document).on('ready page:change', function () { $.onmount() })