What happens when you type a URL into your browser?
What happens when you type a URL into your browser
High level overview:
- You type a URL in your browser and press Enter
- Browser looks up IP address for the domain (using DNS records and )
- Browser initiates TCP connection with the server (or to the websites CDN, if available)
- Browser sends the HTTP request to the server
- Server processes request and sends back a response
- Browser renders the content
What Happens While a Webpage Is Loading
https://javascript.plainenglish.io/what-happens-while-a-webpage-is-loading-6d645f40a08b
The process of loading a website, from the moment you type in its URL until you see it appear on your screen.
When you visit a website, your computer has to do a lot, and there are a lot of things that can go wrong. In this post, we’ll walk through the process of loading a website, from the moment you type in its URL until you see it appear on your screen.
First of all, before entering the subject, it is necessary to have knowledge about TCP, ISP, DNS and DNS lookup. If you know these topics, you can skip this part.
What is ISP?
ISP stands for Internet Service Provider. It is a company that provides the internet to its customers. For example, if you have a cable connection, then you have an ISP. If you have mobile data connection, then you also have an ISP. The ISP is responsible for sending the data packets from your computer to their destination. The most common companies are AT&T Internet Services, Sparklight in USA; BT, Sky Broadband in UK.
What is DNS?
DNS stands for Domain Name System and it is used to translate domain names like www.google.com or www.facebook.com into IP addresses like 216.58.194.65 and 2a03:2880:21d:80c::2 respectively. This translation process is known as DNS lookup and it happens when you type in a website address in your browser’s address bar or click on a link on a website (hyperlink). A DNS server contains all the information about domain names and IP addresses associated with them, so when someone initiates a DNS lookup request, their computer sends a request to one of these servers which returns back the IP address corresponding with the domain name they entered in their browser’s address bar or clicked on while browsing around online using their network connection.
TCP and TCP Handshake
What happens while page is loading?
There are many steps that happen when you load a website. Let’s examine the process in summary form, then break it down into steps and detail each step.
A request is sent from your browser to a server. The request is usually for a file like an image or a video. The server will send back data if the request was successful. If there was an error, then it will return an error message. The browser then processes this data and displays it on your screen. This whole process takes place over a network of computers called the internet. The network is made up of servers that provide data (like websites), clients (like browsers), and connections between them (like routers). Clients send requests to servers, which respond with either data or an error message depending on whether they can fulfill those requests or not.
Steps:
- Type the url and press enter.
- Browser finds IP address from DNS.
- Browser establishes TCP connection with server
- Browser sends HTTP request to server
- The server receives the request and returns a response
- The browser renders the content returned from the server
1. Type the URL and press Enter.
2. Browser finds IP Address from DNS.
After entering the URL, the browser must first know which server it should connect to. In order to know which server to connect with, it needs to know which IP address it should be directed to from the url address written. The IP address is found with DNS lookup from the name of the website written in the url.
After the browser finds the IP address from DNS, what it needs to do is to establish a TCP connection with the server of this address.
3. Browser establishes TCP Connection with Server
After the browser finds the IP address, it establishes a TCP connection with the server. If the host server has an ssl certificate, ie https, the scheme of the url will do TLS handshake to create a reliable connection.
4. Browser Sends HTTP request to Server
Now there is a connection between the browser and the server. After the TCP connection is established, an http request is created by the browser and a request is made to the server. A response is returned according to this http request from the server.
5. The Server Receives the Request and returns a Response
The server decides how to process the request from the browser according to the request line, headers and body. Then the server fetches the content of this path or creates it dynamically.
If the status code of the response returned from the service is 200, the browser thinks that the operation is successful and renders the content.
Now we know how the server generates the response. Now let’s see how the browser handles this returned response.
6. The browser renders the Content returned from the Server
After the browser receives the response from the service, it first looks at the header of the response. According to the Content-Type field in the header, the browser renders this request. Usually, the Content-Type of the response returned from the first http request to a website is bit HTML and browsers know how to render HTML.
We can call the HTML returned from the service the structure or skeleton of the page. When we examine an HTML file, we can see lines that refer to other files that it needs. These files (Js, Css, images, etc.) are the files that determine how our HTML page will be rendered while rendering.
While the browsers parse and render the HTML file, it sends additional requests to the servers in order to access these files. These requests are generally handled in parallel. After the response from these requests, the browser renders the requested page completely.