Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Complete HTTP Request Lifecycle: From URL to Rendered Page

Tech May 18 3

Complete HTTP Request LifecycleComplete HTTP Request Lifecycle: From URL to Rendered Page

Overview

The complete HTTP request process involves multiple stages from the moment a user enters a URL until the page is fully rendered in the browser. This journey encompasses network communication, server processing, and browser rendering mechanisms.

DNS Resolution

When a user enters a URL, the browser first performs DNS resolution to convert the domain name into an IP adress:

  1. Browser checks its own DNS cache
  2. If not found, checks the operating system's DNS cache
  3. If still not found, checks the hosts file
  4. If all previous steps fail, the browser sends a DNS query to the configured DNS server

TCP Three-Way Handshake

After obtaining the IP address, the browser establishes a TCP connection with the server:

  1. Client sends SYN packet to server
  2. Server responds with SYN-ACK packet
  3. Client sends ACK packet to server

HTTP Request and Response

Once the TCP connection is established, the browser sends an HTTP request:

// HTTP Request Structure
GET /index.html HTTP/1.1
Host: example.com
User-Agent: Mozilla/5.0
Accept: text/html
Connection: keep-alive

The server processes the request and sends back an HTTP response:

// HTTP Response Structure
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
Connection: keep-alive


<html>
<head>...</head>
<body>...</body>
</html>

Browser Rendering Process

The browser processes the HTML response and renders the page through several steps:

1. DOM Tree Construction

The browser parses the HTML document and builds the Document Object Model (DOM) tree, representing the document's structure.

2. CSSOM Tree Construction

The browser parses CSS and builds the CSS Object Model (CSSOM) tree, representing the styles applied to the document.

3. Render Tree Construction

The browser combines the DOM and CSSOM trees to create the render tree, which contains only visible elements and their computed styles.

4. Layout

The browser calcultaes the position and size of each element in the render tree.

5. Painting

The browser draws the elements to the screen.

Window Object and Browser APIs

The Window object serves as the global object in browsers, providing access to various browser APIs:

// Window object example
const browserInfo = {
   width: window.innerWidth,
   height: window.innerHeight,
   url: window.location.href,
   userAgent: window.navigator.userAgent
};

// Common Window APIs
window.alert('Hello, World!');
window.open('https://example.com');
window.scrollTo(0, 500);

Nginx Proxy Configuration

Nginx often serves as a reverse proxy for web applications:

// Nginx configuration example
server {
   listen 80;
   server_name example.com;
   
   location / {
       root /usr/share/nginx/html;
       try_files $uri $uri/ /index.html;
   }
   
   location /api/ {
       proxy_pass http://backend-server;
       proxy_set_header Host $host;
   }
}

Webpack Optimization Techniques

Modern web applications use build tools like Webpack to optimize asset delivery:

// Webpack splitChunks configuration
module.exports = {
   optimization: {
       splitChunks: {
           chunks: 'all',
           cacheGroups: {
               vendors: {
                   test: /[\\/]node_modules[\\/]/,
                   name: 'vendors',
                   priority: -10
               },
               antd: {
                   test: /[\\/]node_modules[\\/](@ant-design|antd)[\\/]/,
                   name: 'antd',
                   priority: -9
               }
           }
       }
   }
};

Performance Considerations

Several factors impact page loading performance:

  • DNS resolution time
  • TCP connection establishment
  • HTTP request/response size
  • Number of HTTP requests
  • Rseource compression
  • Caching strategies

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.