What happens when you type a URL into your browser?

Every day, we open our browser and navigate to our favourite websites by typing in their url or simply clicking on a link. Do you know what happened in the background after you typed the url or just clicked a link? How do you acquire the stuff you want?

This blog will examine the entire process. The processes involved are, such as the browser, operating system, ISP (internet service provider), servers, and everything else, because it is essential to understand where things can go wrong.

Websites are collections of files such as html, CSS, javascript, and pictures. They must be accessible to everyone from anywhere, thus hosting them on your local system is insufficient. As a result, we require an external powerful computer that is connected to the internet, i.e. a server, via which anyone may access such files.

When we write a URL such as "https://developercommunity/hello-world", our browser determines which server on the internet is hosting the files. It accomplishes this by searching domain "developercommunity" for the unique address known as IP. Every device connected to the internet has an IP address. "168.191.10.171" is the structure of an IP address (essentially an IPV4 address). However, these numbers are difficult to remember, thus domain names such as "developercommunity" are used because they are easier to remember. It's the same as our phone's contacts app.

Our contacts app searches for numbers by name, just as DNS (domain name system) does in the internet world. DNS allows browsers to locate servers on the internet by using domain names in URLs. More information on DNS can be found here .

The process is similar whether you type a url in browser or simply clicks on a link.

The Process

Let's breakdown this step

scheme

https:// is a scheme. https stands for (hypertext transfer protocol), and it instructs the browser to connect to the server using transport layer security, or TLS. TLS is an encryption method used to safeguard internet communication. Data transmitted over the internet is encrypted. There are additional protocols as well, such as ftp:// mailto://.

domain

"developercommunity" is domain here. It holds the IP address of the specific server.

resource

when we type a url, hello-world is the name of resource on internet which we want to view.

  • Browser looks up for IP address for domain

When we enter the URL into the browser, it determines which server is hosting the specified files. This is accomplished by searching for the IP address using the domain you entered. It accomplishes this through DNS lookup.

DNS lookup is a pretty quick procedure. DNS data is cached at many levels, from the browser's cache to the ISPprovider. The browser first examines its cache, then the operating system cache, and finally the router cache. If the browser is unable to locate the associated IP address, it performs a recursive DNS lookup. It queries several DNS servers, which in turn queries further numerous DNS servers for an IP address. When the browser discovers the IP address, it is time to connect to the server.

  • Browser initiates TCP connection with server

TCP is a shorthand for Transmission Control Protocol. It is a key protocol. TCP is connection-oriented, which implies that a connection must be established between the client and the server before data can be transferred. Before establishing a connection, the server must be listening for connection requests from clients. TCP organises data for transmission between a server and a client. It ensures the integrity of data transmitted via a network.

Once browser find the server it establishes the TCP connection, if https is used a TLS handshake takes place that secures the communication.

  • Browser sends the request to server

The client now sends an HTTP request to the server, which includes methods (GET, POST, PUT, PATCH, DELETE), headers (information about the request), and the request body.

  • Server processes the requests and responds with a response

The server takes the request and based on methods, headers and body it decides how to process the data.

For example if the method is GET /hello-world the server gets the content of the resource hello-world and sends back to the client.

After receiving the response, the browser renders the data based on the Content-Type in the response headers. If the Content-Type is text/html, the browser recognises it as an HTML page and renders it appropriately.