10

I'm trying to make "many" xhr request but it seems that every time it waits for the answer before making another request. It's like XHR makes a queue and always wait for the previous request to finish.

What can I do to run more simultaneous xhr request?

$('body').delegate('.download','click', function(evt){
        evt.preventDefault(); // Not related

        var xhr = new XMLHttpRequest();
        xhr.open('GET', "proxy.php?" + this.href, true);
        xhr.responseType = 'blob';

        xhr.onload = function() {
            if (this.status == 200) {              
                var blob = new Blob([this.response], {type:'audio/mp4'});

                console.log(blob.size);
                if(blob.size > 0){
                    $("<a>").attr({
                        download: name,
                        href: URL.createObjectURL(blob),
                        target: "_blank"
                    })[0].click();
                }
            }
        };  
        xhr.send();
    });
NIMISHAN
  • 1,265
  • 4
  • 20
  • 29

2 Answers2

11

Not a lot.

Browsers enforce a limit on:

  • The number of parallel HTTP requests to a given origin
  • The number of parallel HTTP requests in total (this is a larger limit)

If you split your requests between more originals you might find your constraint raised from the first to the second of the above.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
2

Try to find something about http2, there is some info. Http2 protocol have better supporting of parallel requests.

Alex Nikulin
  • 8,194
  • 4
  • 35
  • 37