How to disable $ http requests in angularjs?

I am creating a user interface for a data importer using angularjs. The angular application will crunch through the original data source (spreadsheet or something else) and send GET / POST to the API to create / update records on the server and receive changes, etc.

If a user imports thousands of records, I probably don’t want to open thousands of ajax calls right away (not that angular will be able to receive all requests sent before the first completion), My thought was to add some kind of connection pool so that it it was possible to disable up to 10 or 50 or so immediately after ajax calls.

Does angular already have a built-in throttling feature for ajax calls? I know that I can build one without any problems, but I do not want to reinvent the wheel, if there is something there. Can anyone recommend any tools / plugins for this? I know there are several for jquery, but I hope to avoid jquery as much as possible for this project.

+7
javascript angularjs ajax
source share
1 answer

Studying this, I found that according to this issue and this page , browsers automatically redirect HTTP requests to the same server somewhere between 6 and 13 simultaneous requests, and they queue additional requests until other requests are completed. Therefore, apparently, no action is required, and I can just let my code fly.

I looked at angular-http-throttler (suggested by nathancahill), but (1) it duplicates what browsers already do themselves, and (2) it does not (currently) have an error management mechanism, so if the server does not respond, or if it was a bad request, it does not reduce the number of requests, so the queue is clogged up forever.

Giving the browser queue too many requests at the same time can cause memory / performance problems when working with very large amounts of data. I looked at various methods for creating a fixed-length queue in javascript, where it can turn off the callback when the queue location becomes available, but the non-blocking nature of javascript makes such a queue complex and fragile ... I hope you won’t have to go into this direction (I don't mean a lot of data), and browser throttling will suffice for me.

+3
source

All Articles