Sobes.tech
Middle

What happens when you enter an address like google.com in your browser?

sobes.tech AI

Answer from AI

  1. URL Parsing: The browser breaks down the URL into components: protocol (HTTP/HTTPS), domain name (google.com), and path (/).

  2. Finding the IP address:

    • The browser checks its DNS cache.
    • The operating system checks its DNS cache.
    • The system requests the DNS server (usually provided by the provider).
    • The DNS server recursively queries root, TLD, and authoritative DNS servers until it finds the IP address for google.com.
    • The IP address is returned to the browser.
  3. Establishing TCP connection:

    • The browser establishes a TCP connection with the server at the found IP address using a three-way handshake (SYN, SYN-ACK, ACK).
  4. SSL/TLS Handshake (for HTTPS):

    • The client and server agree on encryption algorithms.
    • The server sends its certificate.
    • The browser verifies the certificate.
    • The parties exchange encryption keys for a secure connection.
  5. Sending the HTTP request: The browser sends an HTTP request to the server containing the method (GET), path, headers (Host, User-Agent, Accept, etc.), and possibly a body.

    GET / HTTP/1.1  
    Host: google.com  
    User-Agent: Mozilla/5.0 (...)  
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8  
    
  6. Server processes the request:

    • The server receives the request.
    • The server processes the request (e.g., executes application logic).
    • The server forms an HTTP response.
  7. Receiving the HTTP response: The browser receives the HTTP response from the server containing the status code (e.g., 200 OK), headers (Content-Type, Content-Length, etc.), and the response body (HTML page, images, CSS, JS, etc.).

    HTTP/1.1 200 OK  
    Content-Type: text/html; charset=UTF-8  
    Content-Length: XXXX  
    ...  
    
    <!doctype html>...  
    
  8. Rendering the page:

    • The browser starts parsing the HTML code.
    • When it encounters links to CSS, JavaScript, or images, the browser makes additional requests to fetch them (steps 2-7 are repeated for each resource).
    • The browser constructs the DOM tree from HTML.
    • The browser constructs the CSSOM tree from CSS.
    • The browser builds the rendering tree by combining DOM and CSSOM.
    • The browser executes JavaScript (which can modify DOM and CSSOM).
    • The browser calculates the layout of elements on the page.
    • The browser paints the elements on the screen.