Re-rendering of a specific js file with turbo included

I work with Rails 4 and would like to use the built-in Turbolink stone. I am pleased with everything he does, except that I would like to reload one of the js files with every page request.

In other words, I would like a particular js file to ignore turbolinks, how can I do this?

+6
source share
1 answer

You can use the "page: load" event from turbolinks to connect the initialization function to it. It will always be called when turbolinks fully loads your new page.

 function initialize() { //js code what you want run always } $(document).ready(initialize); $(document).on('page:load', initialize); 

If you use jQuery a lot, it is useful to install in your Gemfile

 gem 'jquery-turbolinks' 

and your application.js

 //= require jquery //= require jquery.turbolinks 

Turbolinks has two other useful events:

 page:fetch //when new page begin to download page:change //when the page has changed over 
+7
source

Source: https://habr.com/ru/post/945845/


All Articles