Disable Turblinks every X requests
PJAX/Turbolinks are awesome, but if you like to drop JS plugins on your page, the browser will leak memory like sieve.
Yeah you can inspect the plugins and make them more friendly to JavaScript garbage collection. Or you can parachute this fella into your application.js:
$(document).on('page:load', function(){
Turbolinks.counter = Turbolinks.counter || 0;
Turbolinks.counter++;
if (Turbolinks.counter > 50) {
console.log('Clense thy browser from your memory leak sins!');
document.body.setAttribute('data-no-turbolink', true);
}
});
It increments a counter, and when the counter reaches 50 it adds a data-no-turbolinks to document body and next click will trigger full page refresh.
Mom's going to fix it all soon
Mom's coming around to put it back the way it ought to be
https://www.youtube.com/watch?v=uCEeAn6_QJo
Written by Wojtek Kruszewski
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Tool
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#