What happens when you type URL in your browser


What happens when you type URL in your browser

1. User Inputs URL: www.google.com

When a user enters the website www.google.com in the browser, the browser initiates the page loading process and follows the steps below.

2. DNS Resolution

a. Browser Cache Lookup

  • Check if the browser cache has the IP address for www.google.com.

b. Local DNS Server Query

  • If not found in the browser cache, send a resolution request to the local DNS server.

c. Root DNS Server Query

  • If the local DNS server has no cache, query the root DNS server for the DNS server address of the top-level domain.

d. Top-Level Domain DNS Server Query

  • The root DNS server responds with the DNS server address for the .com top-level domain.

e. Google DNS Server Query

  • The local DNS server queries the DNS server for .com to obtain Google’s DNS server address.
  • The local DNS server queries Google’s DNS server to get the IP address for www.google.com.

3. Establish TCP Connection

a. Browser Uses Obtained IP Address to Establish TCP Connection with Google Server on Port 80.

b. TCP Three-Way Handshake

  • Browser sends a SYN packet to the Google server, indicating a connection request (sequence number A).
  • Google server receives the SYN packet and responds with an ACK and a SYN (sequence number B, acknowledgment number A+1), indicating agreement to establish the connection.
  • Browser receives the ACK and SYN, sends an ACK to the Google server (sequence number A+1, acknowledgment number B+1), confirming successful connection establishment.

4. Send HTTP Request

a. Build HTTP Request Message

  • Request line: Includes request method (GET), URL path (/), and protocol version (HTTP/1.1).
  • Request headers: Include host, user agent, cache control, and other information.
  • Request body (usually empty for GET requests).

b. Encapsulate HTTP Request Message

  • Encapsulate the constructed request message into a TCP data packet.

c. Send HTTP Request

  • Send the encapsulated HTTP request message to the Google server through the TCP connection.

5. Server Processes Request

Once the Google server receives the HTTP request message from the browser, it begins processing the request.

a. Google Server Parses Request

  • The Google server parses the HTTP request message, extracting relevant information.

b. Backend Processing

  • Execute application logic, which may involve database queries, business logic processing, etc.
  • Generate data to be returned to the client.

6. Send HTTP Response

Once the server generates response data, it builds an HTTP response message and sends it back to the browser.

a. Build HTTP Response Message

  • Status line: Includes protocol version (HTTP/1.1), status code (e.g., 200 for success), status message (OK).
  • Response headers: Include server information, content type, content length, cache control, etc.
  • Response body: Contains data generated by the server, such as HTML page content.

b. Encapsulate HTTP Response Message

  • Encapsulate the constructed HTTP response message into a TCP data packet.

c. Send HTTP Response

  • Send the encapsulated HTTP response message back to the browser through the TCP connection.

7. Browser Renders Page

Once the browser receives the HTTP response from the server, it begins rendering the page.

a. Receive HTTP Response

  • The browser receives a TCP data packet containing the HTTP response message.

b. Parse Response

  • Parse the status line to retrieve the status code.
  • Parse response headers to get server information, content type, cache control, etc.

c. Render Page

  • Parse HTML, CSS, and execute JavaScript to build the Document Object Model (DOM) and Cascading Style Sheets Object Model (CSSOM). Subsequently, generate a rendering tree while simultaneously performing layout and drawing, ensuring each node’s accurate position on the screen and direct rendering onto the screen.

d. Display Page

  • Users see the fully rendered page, enhancing interactivity.



Enjoy Reading This Article?

Here are some more articles you might like to read next:

  • 2379. Minimum Recolors to Get K Consecutive Black Blocks
  • 2471. Minimum Number of Operations to Sort a Binary Tree by Level
  • 1387. Sort Integers by The Power Value
  • 2090. K Radius Subarray Averages
  • 2545. Sort the Students by Their Kth Score