從在瀏覽器輸入URL到頁面加載完成所發生的

大致意思就是:如果有cache就直接顯示。否則就在本機找IP,通過DNS找到IP並返回給瀏覽器。然後瀏覽器通過TCP和server之間溝通,server返回數據或者錯誤信息。然後就把數據render到browser。

例如我要打開facebook.com,值得一提的兩點:一是可能會重定向網頁,如從http://facebook.com到http://www.facebook.com。二是發送的http GET請求裏是包含cookie的

關於頁面的圖片,音頻,視頻的加載順序,可以自定義來提高初始加載速度。

此外還可以考慮到CDN(content delivery network)的involve

What are the advantages and disadvantages of using CDN?

  • The disadvantages may be that it costs money, and it adds a bit of complexity to your deployment procedures.

  • The main advantage is an increase in the speed with which the content is delivered to the users.

When to use CDN?

  • It will be most effective when you have a popular public website with some type of static content (images, scripts, css, etc).

Is CDN a performance booster?

  • In general, yes. When a specific request is made by a user, the server closest to that user (in terms of the minimum number of nodes between the server and the user) is dynamically determined. This optimizes the speed with which the content is delivered to that user.

In an extremely rough and simplified sketch, assuming the simplest possible HTTP request, no proxies and IPv4 (this would work similarly for IPv6-only client, but I have yet to see such workstation):

  1. browser checks cache; if requested object is in cache and is fresh, skip to #9
  2. browser asks OS for server's IP address
  3. OS makes a DNS lookup and replies the IP address to the browser
  4. browser opens a TCP connection to server (this step is much more complex with HTTPS)
  5. browser sends the HTTP request through TCP connection
  6. browser receives HTTP response and may close the TCP connection, or reuse it for another request
  7. browser checks if the response is a redirect (3xx result status codes), authorization request (401), error (4xx and 5xx), etc.; these are handled differently from normal responses (2xx)
  8. if cacheable, response is stored in cache
  9. browser decodes response (e.g. if it's gzipped)
  10. browser determines what to do with response (e.g. is it a HTML page, is it an image, is it a sound clip?)
  11. browser renders response, or offers a download dialog for unrecognized types

Again, discussion of each of these points have filled countless pages; take this as a starting point. Also, there are many other things happening in parallel to this (processing typed-in address, adding page to browser history, displaying progress to user, notifying plugins and extensions, rendering the page while it's downloading, pipelining, connection tracking for keep-alive, etc.).

**************************************************************************************************************************************************************************

First the computer looks up the destination host. If it exists in local DNS cache, it uses that information. Otherwise, DNS querying is performed until the IP address is found.

Then, your browser opens a TCP connection to the destination host and sends the request according to HTTP 1.1 (or might use HTTP 1.0, but normal browsers don't do it any more).

The server looks up the required resource (if it exists) and responds using HTTP protocol, sends the data to the client (=your browser)

The browser then uses HTML parser to re-create document structure which is later presented to you on screen. If it finds references to external resources, such as pictures, css files, javascript files, these are is delivered the same way as the HTML document itself.


Reference:

http://stackoverflow.com/questions/2092527/what-happens-when-you-type-in-a-url-in-browser

http://fex.baidu.com/blog/2014/05/what-happen/

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章