When you type a URL in the browser!
Tags: beginners, codenewbie, browser, url
Published: 2021-10-31 07:57:26

## Introduction

Have you ever wondered what exactly happens when you type an URL in the browser and press enter? In this blog, we will see what happens in the background, step by step when we type any URL.
If you want to have a better understanding of this article,then i would recommend you to have an overview of [URL and DNS](https://dev.to/namitmalasi/url-and-dns-explained-4aef).

### 1. You enter URL in the browser
It basically means that you want to reach the server where the site is hosted. for example, if you are searching for facebook.com then, you are searching for the server where facebook .com is hosted.

### 2. The browser looks for the IP Address in the DNS(Domain name server)
  a) The browser maintains a cache of the DNS records for some fixed amount of time. So, it is the first place to run a DNS query.

b) If the browser doesn't contain the cache then it requests to the Operating System as the OS also maintains a cache of the DNS records.

c) If your computer doesn't have the cache, then it searches the routers as routers also have the cache of the DNS records.

d) If all above steps fail, the browser would move on to the ISP. Your ISP maintains it's own DNS server which includes a cache of DNS records which the browser would check.

If the requested URL is not in the cache, ISP’s DNS server initiates a DNS query to find the IP address of the server that hosts facebook.com.
The purpose of a DNS query is to search multiple DNS servers on the internet until it finds the correct IP address for the website.

### 3. The Browser initiates a TCP connection with the server.
When the browser receives the IP address, it will build a connection between the browser and the server using the internet protocol. The most common protocol used is TCP protocol. The connection is established using a [three-way handshake](https://www.guru99.com/tcp-3-way-handshake.html).

### 4. The browser sends an HTTP request to the server.
Once the TCP connection is established, it is time to start transferring data! The browser will send a GET request asking for facebook.com web page.

Sample Get Request:
![Sample Get Request](https://media-exp1.licdn.com/dms/image/C5112AQGhbJSc5YTomg/article-inline_image-shrink_1500_2232/0/1559318572982?e=1641427200&v=beta&t=b0enUMgQMYHkuGUQD9iSppidf6-qb5Qo8bBw-cP1yFI)


### 5. The server handles the request and sends back a response.
The server handles the HTTP request and sends a response. The server response contains the web page you requested as well as the status code, compression type (Content-Encoding), how to cache the page (Cache-Control), any cookies to set, privacy information, etc.

Example HTTP server response:
![Example HTTP server response:](https://media-exp1.licdn.com/dms/image/C5112AQGQs0X5LR4eoA/article-inline_image-shrink_1500_2232-alternative/0/1559318638805?e=1641427200&v=beta&t=n4GTWBBE_YQMp_MZHsNRejx2n-zEeCZtbC2K3ptyAcQ)


### 6. The browser displays the HTML content.
The browser displays the HTML content in phases. First, it will render the bare bone HTML skeleton. Then it will check the HTML tags and sends out GET requests for additional elements on the web page, such as images, CSS stylesheets, JavaScript files etc.
At the end, you’ll see facebook.com appearing on your browser.

## Conclusion
I really hope that you enjoyed reading this article and learned something from it. If you have any doubt or you think i missed something let me know in the comments.
You can connect with me on:

Twitter:[Namit Malasi](https://twitter.com/namitmalasi)