The following is a guest post by Li Ouyang and originally appeared on her blog. Li is currently a student a The Flatiron School. You can learn more about her here, or follow her on twitter here. We’ll be publishing the rest of this mini-series of blog posts as they are released.
Sometimes, it’s the simple questions that trips me up. I’ve been using the internet for the better majority of my life, and I’m even silly enough to believe I can build things for the web. There has been one piece missing to my coding foundation: how does the internet work?
Thanks to this presentation, here is what’s happening everytime you visit a website. P.S. Don’t worry if this sounds like mumbo jumbo.
-
Browser checks cache; if requested object is in cache and is fresh, skip to step 9.
-
Browser asks operating system for server’s IP address.
-
OS makes a Domain Name Server (DNS) lookup and replies the IP address to the browser.
-
Browser opens a TCP connection to server (even more complex with HTTPS).
-
Browser receives HTTP response and may close the TCP connection, or reuse it for another request.
-
Browser checks if the response is a redirect, authorization request, error, etc. These are handled differently from a normal response.
-
If cacheable, response is stored in cache.
-
Browser decodes response.
-
Browser renders response.
-
Browser sends further asynchronous(AJAX requests)
The first step to using the internet is typing in a URL, like google.com into your browser’s address bar. But how does your browser know where the website lives? Think of the URL like someone’s name and you want to give this person a call. Before the internet, you’d probably pull out one of those thick, yellow phone books. Then, by alphabetical order, you’d look up the name and scan right to find the number. Ok, but maybe that phone book is clunky, and you’re sick of looking up the same people over and over again. Maybe you have a personal address book and you look there instead!
Same thing with the internet. You may have given your browser a URL (someone’s name), but the browser needs to look up the IP address(someone’s phone number). The first thing your browser does is it looks through it’s cache (or phonebook). Your cache stores recently-used information in an easily accessible place. In fact, your computer has access to a couple caches! First it checks on the cache’s stored on your computer for an IP address. If nothing comes up, your browser makes a DNS lookup. The DNS is like a compilation of the most massive phone books you can imagine. In fact, they’re interactive phonebooks that help each other out. The image to the right does an amazing job illustrating this process.
You now understand how the internet is organized and how your computer implements it! Next up is HTTP requests and responses. Stay tuned.