This is dead simple, but it’s an important improvement if you are using turbolinks on your Rails app. It’s most relevant if you have pages that have some significant database heavy lifting to do because without it your users won’t know that your app is working. A tiny bit of really simple javascript is all you need to add a spinner or some other alert to your site:
$(document).on('page:fetch', function() {
$('#page_loading').show();
});
$(document).on('page:change', function() {
$('#page_loading').hide();
});
Put whatever suits your fancy in #page_loading and you are off to the races.
Hat tip to Matt DeLeon who helped me figure out all the changes TroopTrack needed to work with Turbolinks.




2 responses so far ↓
1 Matt // Nov 28, 2012 at 4:06 pm
Do you need the page:change callback? Won’t the contents of the document be replaced by the page retrieved from the server, where presumably #page_loading is hidden already?
2 David Christiansen // Dec 11, 2012 at 10:37 am
You might be right. I’ll have to try it and see.
Leave a Comment