Fundamentals 15 min read

What Really Happens Behind the Scenes When You Visit a URL?

This article walks through every step that occurs when you type a URL— from the browser’s DNS lookup and HTTP request, through server processing, redirects, HTML rendering, and subsequent resource and AJAX calls—revealing how browsers, servers, and CDNs cooperate to deliver a web page.

21CTO
21CTO
21CTO
What Really Happens Behind the Scenes When You Visit a URL?

As a software developer, you should understand the layered process behind a web request, including the browser, DNS, HTTP, server processing, and rendering.

1. Enter the URL in the browser

2. Browser looks up the domain’s IP address

DNS lookup proceeds through several caches:

Browser cache – the browser stores DNS records for a short period (2–30 minutes).

OS cache – if the browser cache misses, the OS is queried (e.g., gethostbyname on Windows).

Router cache – the router may have its own DNS cache.

ISP DNS cache – the ISP’s DNS server is checked next.

Recursive search – the ISP’s DNS server performs a recursive lookup from the root to the authoritative server.

3. Browser sends an HTTP request to the web server

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 request includes headers that describe what the browser can accept, its identity, and any cookies associated with the domain.

4. Server returns a 301 permanent redirect

HTTP/1.1 301 Moved Permanently
Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Location: http://www.facebook.com/
P3P: CP="DSP LAW"
Pragma: no-cache
Set-Cookie: made_write_conn=deleted; expires=Thu, 12-Feb-2009 05:09:50 GMT; path=/; domain=.facebook.com; httponly
Content-Type: text/html; charset=utf-8
X-Cnection: close
Date: Fri, 12 Feb 2010 05:09:51 GMT
Content-Length: 0

Redirects help consolidate SEO ranking and improve cache consistency.

5. Browser follows the redirect and sends a second request

GET http://www.facebook.com/ HTTP/1.1
Accept: application/x-ms-application, image/jpeg, application/xaml+xml, ...
Accept-Language: en-US
User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; ...)
Accept-Encoding: gzip, deflate
Connection: Keep-Alive
Cookie: lsd=XW...; c_user=21...; x-referer=...
Host: www.facebook.com

6. Server processes the request

Web server software (e.g., IIS, Apache) receives the request, maps the URL to a file or invokes a request handler such as ASP.NET, PHP, or Ruby, reads parameters and cookies, possibly updates data, and generates an HTML response.

7. Server sends an HTML response

HTTP/1.1 200 OK
Cache-Control: private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Sat, 01 Jan 2000 00:00:00 GMT
P3P: CP="DSP LAW"
Pragma: no-cache
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
X-Cnection: close
Transfer-Encoding: chunked
Date: Fri, 12 Feb 2010 09:05:55 GMT

The body is compressed with gzip; after decompression the browser receives the full HTML document.

8. Browser starts rendering the HTML

Even before the entire document is received, the browser begins layout and painting.

9. Browser fetches embedded resources

Additional requests are made for images, CSS stylesheets, and JavaScript files, each undergoing the same DNS lookup and HTTP cycle.

10. Browser sends asynchronous (AJAX) requests

Modern pages keep a background connection for updates; for example, Facebook chat uses long‑polling to fetch friend‑status information.

Summary

Understanding each network module helps you see how browsers, DNS, HTTP, servers, CDNs, and AJAX cooperate to deliver a web page.

Original English title: "What really happens when you navigate to a URL" Translation by: 寒冬星空 Source link: http://www.cnblogs.com/wenanry/archive/2010/02/25/1673368.html
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

HTTPDNSBrowserajaxclient-serverweb fundamentals
21CTO
Written by

21CTO

21CTO (21CTO.com) offers developers community, training, and services, making it your go‑to learning and service platform.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.