All my .js files look like this:
function function_name(){
.....
some code
.....
}
$(document).ready(function_name);
$(document).on('page:load', function_name);
I use setInterval(some_function, 7000)
, Event handlers like $(document).on('click', '.blah-blah', function(){...})
. Unfortunately, these stuff calls multiple times if I a have more than one request to server via turbolinks (using turbolinks session). Actually amount of calls equals to the amount of server requests.
For instance, I have <button id="button"></button>
and js event handler, handler executes as many times as requests in turbolinks session I have. It's so annoying)
I'd like you to find out how to keep turbolinks turned on and avoid multiple calls inside js files. Thanks.
You have two options:
In the code that does things like sets the interval or adds a handler, check first to see if the interval or handler already exists, and don't add another one if there's already one there.
Attach to one of the other events from turbolinks like "page:before-change"
or "page:before-unload"
and remove the interval or handler in there.