简体   繁体   English

浏览器会阻止同时执行几个异步XMLHttpRequest上的JS执行吗?

[英]Do browser block JS execution on several simultaneous async XMLHttpRequest?

I've heard that browsers issue only limited number of simultaneous requests (like 2 or 6). 我听说浏览器仅发出有限数量的同时请求(例如2或6)。

If I issue several XMLHttpRequest.send() do my JS code blocked at some point (for example on send call)? 如果发出多个XMLHttpRequest.send() ,我的JS代码是否在某个时候被阻塞(例如在send调用时)?

Or all requests collected in browser queue and only portion of them will be sent to network? 还是在浏览器队列中收集的所有请求,只有其中一部分会发送到网络?

Correct, a browser will only send a certain number of requests in parallel. 正确,浏览器只会并行发送一定数量的请求。 Your code however won't block unless you send synchronous xhr requests (which you most likely don't do). 但是,除非您发送同步的xhr请求(您很可能不会这样做),否则您的代码不会被阻止。

When the max. 当最大 parallel request limit is reached the browser will queue the other requests and process them as soon as another running requests has finished. 达到并行请求限制时,浏览器将使其他请求排队并在另一个正在运行的请求完成后立即处理它们。 But this mechanism does not affect your code. 但是这种机制不会影响您的代码。 Only difference is that request durations (duration = time the requests completes - time issueing the request in JS) increase. 唯一的区别是请求持续时间(持续时间=请求完成的时间-用JS发布请求的时间)增加了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM