Chapter 1.1.2 - What is a browser?
A browser is a kind of software that allows you to very conveniently navigate the web. Here's how it does it:
- When you go to some website, your browser contacts the DNS server to learn what is the real IP address for its domain name (recall our Apple example in the DNS section).
- Once your browser knows the IP address, it sends a
GETrequest to that IP address describing what it wants to retrieve. For example, when you visited this page, your browser sent aGETrequest to the IP address of the server that's hosting this page and asked to retrieve the HTML filechapter-1.2.html. - Once the browser receives the requested HTML file back, it starts to analyze it and build a DOM-tree (more on that in Chapter 2). For now, think of that as an internal structure of the website. If a file that you requested is not HTML, then other methods of displaying are used (for example, a PDF file would be displayed with a PDF reader). If your browser can't display a file, it prompts to download it to your hard drive. Every website you visit uses HTML.
- Once the browser has created the DOM-tree of the HTML page, it starts to render it. Meanwhile, if the page contains images, your browser sends additional
GETrequests to retrieve those files so that it can display them.
All of that happens within seconds, if not less!
One important thing that you should know is that, by default, if you don't specify a file and only specify the directory that you want to retrieve when going to a website, your browser will send a request for index.html. For example, when you visit https://www.apple.com/mac/, you browser actually sends a request for https://www.apple.com/mac/index.html, retrieves index.html, and renders it. Click both links to confirm that they lead to the same destination!
By now you may have noticed that the website addresses after the domain name look like addresses on your computer's filesystem. It's because they are! Essentially, a server is hosting a directory and you can access its files remotely. (Some website architectures are more complicated and actually generate files when you request them, but you don't need to worry about that.)
Exercise
Press Cmd+Shift+C (or F12) to go to Firefox's console, click the "Network" tab, then visit any website. Look at how many HTTP requests are needed just to display one website! Note also that the first request is a request for an .html file.