Shielding is a Rails gem with javascript utility to abort pending AJAX calls. Please refer to this StackOverflow thread for more details.
Add this line to your application's Gemfile:
gem 'shielding'
And then execute:
$ bundle
Or install it yourself as:
$ gem install shielding
Shielding keeps track of all the ongoing AJAX calls in a $.xhrPool
array,
and to abort all of them, simply call $.xhrPool.abortAll()
.
When to abort all the ongoing AJAX calls is the client app's decision. For example, we may want to abort all the pending AJAX calls when Turbolinks start to fetch a target page:
$(document).on('page:fetch', function() {
$.xhrPool.abortAll();
});
- Fork it ( http://github.com/artsy/shielding/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request