Pages

Saturday, August 31, 2024

Web Page Loading Process



The process of loading a web page involves several intricate steps.

Let's dissect each phase:

1. DNS Resolution:
• Browser checks local DNS cache
• If not found, queries DNS resolver
• Resolver searches through DNS hierarchy: Root > TLD > Authoritative
• IP address of the server is returned

2. TCP Connection Establishment:
• Three-way handshake: SYN, SYN-ACK, ACK
• TLS handshake for HTTPS (adds 2 round trips)

3. HTTP Request:
• Browser sends GET request (or POST, PUT, etc.)
• Includes headers: User-Agent, Accept, Cookie, etc.

4. Server Processing:
• Web server receives request
• Application server processes (e.g., PHP, Node.js)
• Database queries if needed
• Generates HTML response

5. Response Transmission:
• Server sends HTTP response
• Headers: Content-Type, Content-Length, Set-Cookie, etc.
• Body: HTML content

6. Browser Processing:
a. HTML Parsing:
• Constructs DOM tree
• Identifies external resources (CSS, JS, images)

b. CSS Processing:
• Builds CSSOM tree
• Combines with DOM to create Render tree

c. JavaScript Execution:
• Parsed and executed by JS engine
• Can modify DOM and CSSOM

d. Layout Calculation:
• Computes exact position and size of each element

e. Painting:
• Converts layout to pixels on the screen

7. Additional Resource Loading:
• Images, fonts, videos loaded asynchronously
• May trigger reflow and repaint

8. Post-Load Optimizations:
• Lazy loading of off-screen content
• Preloading anticipated resources
• Service worker caching for offline access

Performance Considerations:
• Minimize HTTP requests
• Optimize critical rendering path
• Implement effective caching strategies
• Use CDNs for global performance
• Compress and minify assets


No comments:

Post a Comment