What happens when you type a URL in the web browser and hit enter?
Parse URL
Look for IP address of the domain in DNS
Establish TCP connection with the server
Make HTTP request
Severs send the HTTP response
Browser receives the response, parse the response and display the content
Parsing the URL: Browser parses the URL to extract various components such as the protocol (HTTP, HTTPS), domain name (e.g.,www.example.com), path, query parameters, and other fragments.
The browser looks for the IP address of the domain name (locate the server hosting that website) in the DNS (Domain Name System)
DNS is a list of URLs and their corresponding IP address (like a telephone book). We can access the website directly by typing the IP address but imagine remembering a group of numbers to visit any site.
The DNS checks at the following places for the IP address.
Check Browser Cache: The browser maintains a cache of the DNS records for some fixed amount of time.
Check OS Cache: 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.
Router Cache: If your computer doesn't have the cache, then it searches in the router cache of the DNS records.
ISP (Internet Service Provider) Cache: If the IP address is not found till this then it is searched at the cache that ISP maintains of the DNS records. If not found here also, then ISP’s DNS recursive search is done. In "DNS recursive search", a DNS server initiates a DNS query that communicates with several other DNS servers to find the IP address.
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.
The browser sends an HTTP request to the server.
Once the TCP connection is established with the server, actual request i.e GET |http://www.google.com is sent.
The server handles the incoming request and sends an HTTP response.
The server processes the request and prepares the response in client requested format i.e. HTML, JSON, XML, etc & adds other details like response status, etc. Once the server is ready with the response, it will be sent back to the client over the established TCP connection.
Browser’sReceiving and Parsing the Response and then Rendering and Displaying Content:
Once the client receives the response from the server, the browser checks theresponse status code i.e 2xx(success response), 3xx(redirecting request),4xx(client error) 5xx(server error), etc.
The browser will try to translate the response based on the received response type. In our case it is HTML, so it will display the html page. If the response is cacheable is will store the response in the browser cache.