What really happens if you navigate to a URL

Source: Internet
Author: User
Tags browser cache

Cold is super uncomfortable, recently a little over-anxiety, seriously look at this classic article, translated as follows, to this meditation!

1. Enter the URL in the browser address field

2, the browser to find the corresponding IP address of the domain name, DNS domain name resolution system in the following order to find:

2.1 browser cache; Sometimes the browser caches DNS lookup records for a short period of time, and the operating system does not tell the browser the lifetime of each DNS record, so the browser caches them at a fixed time (2-30 minutes between different browsers);

2.2 OS cache; In the browser cache, the browser makes a system call, gethostbyname functions, and the operating system has its own cache.

2.3 Router cache;

2.4 The ISP cache on the DNS server, in particular, the network service provider to the Web page Bulk access acceleration of a solution, the current period of access to a larger page in the cache, thereby increasing access speed, the ISP cache mainly cache static pages mainly, such as Sina News page;

2.5 recursive search; The ISP's DNS server starts a recursive search from the root naming server through the COM top-level naming server until the Facebook naming server (assuming the URL address of the request is: facebook.com).

3. The browser sends an HTTP request to the Web server

Take the following request as an example:

GET http://facebook.com/HTTP/1.1

Accept:application/x-ms-application, Image/jpeg, Application/xaml+xml, [...]

user-agent:mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; [...]

Accept-encoding:gzip, deflate

Connection:keep-alive

Host:facebook.com

Cookie:datr=1265876274-[...]; Locale=en_us; Lsd=ww[...]; C_user=2101[...]

The GET request defines the URL address to be requested, and the browser also shows the identity through User-agent, which is accessed by what browser. Accept and Accept-encoding also declare the type of receipt, and the setting of the connection request header tells the server to keep the TCP connection. There are also cookies that record the login user's account password or other user-set information that is sent to the server with each request. These details can be viewed with tools such as fiddle or firebug when optimizing your site.

Note: The slash at the end of the URL http://facebook.com/is also very important, the request browser can add the trailing slash directly, but for example Http://example.com/folderOrFile, the browser cannot automatically add a slash at the end , because Folderorfile is a directory or a file is not very certain, in such a case, the browser when the request without a slash, the server will respond to a redirect, resulting in unnecessary round trips.

4. The Facebook server responds to a 301 permanent redirect status code, informing the browser to access "http://www.facebook.com/" instead of "http://facebook.com/".

The reasons why the server does not respond directly are: One is the search engine ranking, and the other is that multiple URLs with the same content are not friendly to the cache.

5. Browser redirection

6, the server processing requests;

This may seem like a simple task, but in fact, there are a lot of interesting things happening here, even for a simple blog site, not to mention on massively scalable websites like Facebook.

For example, data storage, fragmentation, night data updates, and so on.

7. The server returns a 200 HTML request, and Content-encoding informs the browser that the body portion of the response is compressed by gzip.

8, the browser began rendering HTML;

9. The browser continues to send requests embedded in HTML. Images,css,js, and so on, each address is going through a process similar to the HTML page request, DNS lookup of the domain name, sending the request URL, following the redirect ...

Static files and Dynamic Web pages, can be cached in the browser, some files are directly from the cache, and not through the server, the browser by interpreting the file containing the expires response header settings know how to cache a particular file, and each response will generally have an etag (similar to the version number) , if the browser sees a file that already exists with the same etag, it will immediately interrupt the requested communication line.

A website with a larger number of visits will set up a CDN, cache some static resources, and achieve load balancing.

10. The browser sends an asynchronous AJAX request.

This article references: http://igoro.com/archive/what-really-happens-when-you-navigate-to-a-url/

What really happens if you navigate to a URL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.