URL Requests
Here's what happens behind the scenes when you type in a url in your browser and hit enter:
-
The browser checks its cache for a non-expired, cached response body for the url. If it finds it, it doesn't bother connecting to the url, and instead it just renders the response that it has cached (skip to step 7).
-
Thi is uncommon. Most modern websites give their cache expiry timestamps a value of -1, which means they expire immediately.
-
The browser checks the operating system for the IP address of that url. If it finds it, it skips the IP address lookup and goes straight to that IP address (skip to step 4).
-
This is what usually happens - the OS is good about storing this info for sites you've visited before.
-
A DNS lookup initiates. It has three steps:
-
Root query - The browser goes to one of ~13 root servers that exist, and it tells it the IP address of a server where you can find IPs for websites of the top-level-domain you're looking for (e.g. .com)
-
TLD query - This next server gives you the IP of the nameserver you're looking for (e.g. google).
-
Nameserver query - The nameserver gives you the exact IP address for the specific url you're looking for.
-
The client opens a TCP socket to connect to the server.
-
The client makes an HTTP request
-
The server formulates the correct response
-
This is all the stuff that Rails does.
-
The browser decodes the HTTP response.