简体   繁体   中英

How many times does a browser connect to a web server when retrieving static content?

In HTTP 1.0 I know that a new socket connection is made as soon as the browser sends a new GET request. I was wondering if the browser sends the GET request for each individual file in the website. For example, let's say we have a static website with 3 image files and the index.html file. When we connect to the server, does the browser send 4 separate requests (aka 4 different connections), or does it only connect to the website once and retrieve all the content (aka only 1 connection is enough)?

If you open the developer console in a browser and look at Network (in Chrome) it shows you all of the requests that are made. It will make an individual request for each resource. Also, if an image is used 20 times it will be requested once and displayed 20 times. Although all of these requests are made separately it could still be that they are all done through the same connection as a request and a connection are not the same thing. Hope this gives you a bit of direction. These two links may give you a bit more information on connections to the server.

https://en.wikipedia.org/wiki/HTTP_persistent_connection https://en.wikipedia.org/wiki/HTTP_pipelining

如此答案中所述 (关于HTTP 1.0与1.1),在v1.0中,每个请求都是在单独的连接中发送的,因此该请求为4,但是由于缓存机制(在v1.0 可用),浏览器可能根本不发送任何请求,因此无法打开任何连接。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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