Background
This post will be my dump of software engineer interview questions. Whenever I found anything interesting, I will put it here, so this is an "always a draft" post.
Also, I will try to answer them.
Questions
What happens when you enter a URL into your browser and press enter?
Plenty of little things will happen, like, a key-pressed callback/handler will be called. This handler will get a string value from the text field. The browser will try to parse the value and do something about it.
But I guess that is not the detail level that question meant. Hehe. So I'll continue at a slightly higher level.
After the browser determined that the string is indeed a URL, it will try to chunk the URL into some parts:
- protocol
- hostname
- path
- query-params
Then the browser needs to resolve the IP address of the hostname by looking into DNS records. It will start at its local DNS cache, and if it cannot find it, it will consecutively find it in the OS cache, router cache, ISP DNS server, and ends at some public DNS server.
Then it will try to establish TCP/IP connection using a handshake with the host, by exchanging synchronize(SYN) & acknowledge(ACK) messages.
After the connection is established, if needed/able, the browser will try to make a TLS handshake by exchanging messages.
After the connection is established, the browser then starts to send HTTP requests, with path, headers, and/or body. The host (or by now can be called the server), handles the requests and send back the response.
A response usually got an adequate amount of information for the browser to render something, for example, HTML, JS, or CSS.
Then the browser renders something based on the response, and maybe do another request to the server if required.
References:
- https://medium.com/@kasunpdh/ssl-handshake-explained-4dabb87cdce
- https://www.cloudflare.com/learning/ssl/what-happens-in-a-tls-handshake/
Top comments (0)