1

I have a backbone application that renders many views in parallel and each view is sending multiple REST requests through collections. Now suppose if user closes one view before the http requests for the same have been completed, I see that in the network console, the HTTP requests still continues to fetch the data from the server. This data will never be rendered and will be fetched un-necessarily.

Is there a way we can stop all HTTP requests initiated by the Backbone View as soon as the view gets destroyed.

beNerd
  • 3,314
  • 6
  • 54
  • 92
  • 1
    You can use the abort() method to cancel an ajax request, however that does not stop your server from processing it. :D – Birju Shah Feb 13 '15 at 10:27
  • or you can also look at this http://stackoverflow.com/questions/12749043/is-it-possible-to-stop-backbone-read-requests – Birju Shah Feb 13 '15 at 10:35

1 Answers1

0

From the client you should send xhr.abort(). (Afaik. jquery.ajax() returns xhr as well.) Abort() will end the request. Most of the servers recognize user abort and stop processing, but if you are still worried about this, you should build in pagination.

inf3rno
  • 24,976
  • 11
  • 115
  • 197