Load and execution sequence of a web page?

前端 未结 7 2060
盖世英雄少女心
盖世英雄少女心 2020-11-22 03:15

I have done some web based projects, but I don\'t think too much about the load and execution sequence of an ordinary web page. But now I need to know detail. It\'s hard to

7条回答
  •  时光说笑
    2020-11-22 04:17

    Open your page in Firefox and get the HTTPFox addon. It will tell you all that you need.

    Found this on archivist.incuito:

    http://archivist.incutio.com/viewlist/css-discuss/76444

    When you first request a page, your browser sends a GET request to the server, which returns the HTML to the browser. The browser then starts parsing the page (possibly before all of it has been returned).

    When it finds a reference to an external entity such as a CSS file, an image file, a script file, a Flash file, or anything else external to the page (either on the same server/domain or not), it prepares to make a further GET request for that resource.

    However the HTTP standard specifies that the browser should not make more than two concurrent requests to the same domain. So it puts each request to a particular domain in a queue, and as each entity is returned it starts the next one in the queue for that domain.

    The time it takes for an entity to be returned depends on its size, the load the server is currently experiencing, and the activity of every single machine between the machine running the browser and the server. The list of these machines can in principle be different for every request, to the extent that one image might travel from the USA to me in the UK over the Atlantic, while another from the same server comes out via the Pacific, Asia and Europe, which takes longer. So you might get a sequence like the following, where a page has (in this order) references to three script files, and five image files, all of differing sizes:

    1. GET script1 and script2; queue request for script3 and images1-5.
    2. script2 arrives (it's smaller than script1): GET script3, queue images1-5.
    3. script1 arrives; GET image1, queue images2-5.
    4. image1 arrives, GET image2, queue images3-5.
    5. script3 fails to arrive due to a network problem - GET script3 again (automatic retry).
    6. image2 arrives, script3 still not here; GET image3, queue images4-5.
    7. image 3 arrives; GET image4, queue image5, script3 still on the way.
    8. image4 arrives, GET image5;
    9. image5 arrives.
    10. script3 arrives.

    In short: any old order, depending on what the server is doing, what the rest of the Internet is doing, and whether or not anything has errors and has to be re-fetched. This may seem like a weird way of doing things, but it would quite literally be impossible for the Internet (not just the WWW) to work with any degree of reliability if it wasn't done this way.

    Also, the browser's internal queue might not fetch entities in the order they appear in the page - it's not required to by any standard.

    (Oh, and don't forget caching, both in the browser and in caching proxies used by ISPs to ease the load on the network.)

提交回复
热议问题