瀏覽器限制同一個域名的併發請求數
阿新 • • 發佈:2022-05-25
在ajax中限制同是對同一個域名的併發請求限制
- Chrome 最大併發請求數目為 6,這個限制還有一個前提是針對同一域名的,超過這一限制的後續請求將會被阻塞。
chrome 原始碼寫死的
// Default to allow up to 6 connections per host. Experiment and tuning may // try other values (greater than 0). Too large may cause many problems, such // as home routers blocking the connections!?!? See http://crbug.com/12066. int g_max_sockets_per_group[] = { 6, // NORMAL_SOCKET_POOL 255 // WEBSOCKET_SOCKET_POOL };
實驗驗證 chrome Network 網路 3G
<!-- connection.html --> <html> <body> <img src="/test1.jpg" alt="" /> <img src="/test2.jpg" alt="" /> <img src="/test3.jpg" alt="" /> <img src="/test4.jpg" alt="" /> <img src="/test5.jpg" alt="" /> <img src="/test6.jpg" alt="" /> <img src="/test7.jpg" alt="" /> <img src="/test8.jpg" alt="" /> </body> </html>
- svc node
// connection.js const http = require('http'); const fs = require('fs'); const port = 3010; http.createServer((request, response) => { console.log('request url: ', request.url); const html = fs.readFileSync('./connection.html', 'utf-8'); const img = fs.readFileSync('./test_img.jpg'); if (request.url === '/') { response.writeHead(200, { 'Content-Type': 'text/html' }); response.end(html); } else { response.writeHead(200, { 'Content-Type': 'image/jpg' }); response.end(img); } }).listen(port); console.log('server listening on port ', port);