Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmlhttprequest simultaneous request not working

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();
    });
like image 880
Gregory Wullimann Avatar asked Dec 21 '15 23:12

Gregory Wullimann


2 Answers

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.

like image 92
Quentin Avatar answered Oct 27 '22 01:10

Quentin


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

like image 35
Alex Nikulin Avatar answered Oct 27 '22 00:10

Alex Nikulin