How the Web Works: The Hidden Process Behind Loading a Website

When you type a URL (like priorcoder.com) into your browser’s address bar and press enter, a fascinating series of events begins. These steps are intricate and involve various layers of hardware and software working together to fetch and display the webpage you requested. Let’s break down the process into simple steps and explain each one in detail.

1. Key Press Event: The Journey Begins

When you press a key on your keyboard, several things happen at the hardware level before your computer even knows what key you’ve pressed.

  • Electrical Signal: When you press the “g” key, an electrical circuit is completed in the keyboard, sending a signal to your computer. This signal is converted into a keycode, which the computer interprets as the letter “g.”
  • Virtual Keyboard: On touchscreens, pressing a key triggers a similar process, where a tiny electrical current detects the touch and sends the corresponding keycode.

2. Parsing the URL

Once you’ve finished typing the URL and pressed “Enter,” the browser needs to figure out what you’ve typed. Is it a valid URL, or is it a search query?

  • URL vs. Search Term: The browser checks if what you’ve typed looks like a URL (e.g., priorcoder.com). If it doesn’t have a valid protocol (like http:// or https://) or domain name, the browser might treat it as a search query and send it to your default search engine.

3. Handling Non-ASCII Characters

If the URL contains special characters (like ñ or é), the browser converts them into a format that the web can understand, called Punycode. This ensures that the URL can be properly processed by web servers.

4. Checking HSTS (HTTP Strict Transport Security)

The browser checks a preloaded list of websites that require secure connections (HTTPS). If the website is on this list, the browser will automatically use HTTPS, ensuring your connection is secure from the start.

5. DNS Lookup: Finding the Server

The browser needs to find the IP address of the server that hosts the website. This process is called a DNS (Domain Name System) lookup.

  • Cache Check: First, the browser checks its cache to see if it already knows the IP address.
  • Host File: If it’s not cached, it checks the computer’s host file, which maps domain names to IP addresses.
  • DNS Server: If the IP address is still unknown, the browser asks a DNS server to find it. This is usually your ISP’s server, which might ask other servers if it doesn’t know the answer.

6. ARP Process: Finding the Gateway

Before sending data to the DNS server or the website, your computer needs to know where to send it. The ARP (Address Resolution Protocol) process helps map the IP address of the target server to a physical MAC address on the network.

7. Opening a Socket: Making the Connection

Now that your computer knows where to send the request, it opens a TCP (Transmission Control Protocol) socket to communicate with the server.

  • TCP Handshake: A three-step process ensures that both your computer and the server are ready to send and receive data.

8. TLS Handshake: Securing the Connection

If you’re using HTTPS, a TLS (Transport Layer Security) handshake occurs next. This ensures that the data sent between your browser and the server is encrypted and secure.

  • Certificates: The server sends a public key, which your browser uses to encrypt a session key. Only the server can decrypt this key, ensuring secure communication.

9. Sending the HTTP Request

With the connection established and secured, your browser sends an HTTP request to the server asking for the webpage. This request might look something like this:

GET / HTTP/1.1
Host: google.com

10. Server Response

The server receives your request, processes it, and sends back the webpage’s HTML, along with other resources like CSS files, JavaScript, and images.

  • Response Code: The server also sends a status code (like 200 OK) to indicate whether the request was successful.

11. Parsing HTML: Building the Page

The browser starts parsing the HTML it received from the server. This is the beginning of turning code into the visual webpage you see.

  • DOM (Document Object Model): The browser builds a tree structure from the HTML, representing the page’s structure and content.

12. CSS Interpretation: Styling the Page

Next, the browser processes any CSS it received, which controls the visual style of the page, including colors, fonts, and layouts.

  • Style Rules: CSS rules are applied to the elements in the DOM tree, determining how each element should look.

13. JavaScript Execution: Adding Interactivity

If the page includes JavaScript, the browser’s JavaScript engine executes the code, adding interactivity to the page. This could include things like animations, form validation, or fetching additional data.

14. Page Rendering: Displaying the Content

With the DOM, CSS, and JavaScript processed, the browser can now render the page.

  • Render Tree: The browser creates a render tree, which represents the visual elements on the page.
  • Layout and Paint: The browser calculates where each element should appear on the screen (layout) and then paints the pixels onto the screen.

15. Handling Additional Resources

As the browser renders the page, it might encounter additional resources (like images or scripts) that need to be loaded. The browser repeats the process of sending HTTP requests and receiving responses for these resources.

16. Finalizing the Page

Once all resources are loaded and rendered, the browser considers the page fully loaded. At this point, any JavaScript that was deferred until the end of the loading process is executed.

17. Continuous Interaction

Even after the page is fully loaded, the browser continues to handle user interactions (like clicks, typing, or scrolling) and server communication. JavaScript can modify the page dynamically, and the browser will re-render the affected parts.

Reach Out to me!

DISCUSS A PROJECT OR JUST WANT TO SAY HI? MY INBOX IS OPEN FOR ALL