What happens when you enter a URL in your browser?
The act of opening up a browser window, typing an internet address, and thereby navigating to a webpage is so common and so mundane that it’s easy to forget that this simple act has a lot behind it.
Not only does an understanding of what happens when you enter a URL in your browser satisfy curious minds, knowing how a URL works can help you understand what you need for a website, if you’re just starting out, or help you figure out what’s going wrong with a website—maybe yours—when something goes wrong.
The purpose of a URL
The first step in understanding how a URL works, and specifically what happens when you enter a URL in your browser, is understanding what a URL is and what the purpose of a URL is.
A URL is a “uniform resource locator.” This is more or less a fancy way of saying that it’s a standardized shorthand for finding things on the internet.
The purpose of a URL, then, is to be a kind of address that tells you exactly where a particular “resource”—generally that means some kind of file, whether a webpage, an image, an MP3 file, or something else—can be found on the internet.
But the purpose of a URL goes beyond just this simple meaning. Let’s dig deeper to see how a URL works.
How a URL works
A URL is composed of a few different parts, actually. The core of the URL is the domain name. This is in the form of “example.com.”
Domain name in a URL
At it’s most basic, it’s composed of a top-level domain (for example, .com), plus a second-level domain (in this case, “example”). But often, it will also include a subdomain, most commonly www. Though it could also be “shop,” “help,” “docs,” “news,” etc.
This tells your browser where to look in the DNS system for the webpage (or other resource) you’re looking for (but more on that later).
Protocol in a URL
Before the domain name, there will be a protocol. Usually, this is either http or https. This tells your browser the protocol to use to establish communication with a server.
Path in a URL
The path is the part of the URL after the domain name. It tells the server corresponding to the domain name what folder and filename you’re looking for.
Other parts of a URL
There might also be other parts, like a query, which starts with a ? and follows the path along with parameters. There might also be a # followed by the name of an anchor on a page that enables you to jump directly to a particular spot on a webpage.
Now that we know a little bit more about how a URL works and the purpose of a URL, we can dive in to what actually happens when you enter a URL in your browser.
Step 1: IP Address Lookup
The first thing that needs to happen is your browser needs to get the IP address of the server hosting the web resource you’re trying to access. Giving your browser a URL or a domain name doesn’t actually give it enough information to know where to reach a web server.
For that, it has to translate the domain name in your URL into the IP address of the corresponding server. While a URL is the human readable address for something, the IP address is the number corresponding to the actual location of a particular computer in the internet.
The Domain Name System (or DNS) is the system that creates the correspondance between domain names and IP addresses, so in order to get this IP address, your browser needs to look it up in the DNS using the domain name in the URL you enter in your browser.
Step 2: Initial connection to the server
Once your browser knows where the web server is, it can establish a connection to it. The first layer of connection it needs to establish uses a protocol called Transmission Control Protocol, or TCP This is one of the basic protocols on the internet.
This connection needs to be made before anything can be sent or received between your browser and the web server of the URL you’re trying to go to. The connection consists of data sent and received between your browser and the web server and the protocols responsible for ensuring that these data find their way through your router, your ISP’s network, and other aspects of the internet is TCP.
Once the connection is established, your browser can send and receive pieces of information to and from the web server. While the connection is still being established, these “packets” are essentially empty, but once a connection is established, your browser can exchange application data with the web server. That is, it can send and receive data for the web.
Step 3: Connect using HTTP
You might have been confused in the last section when we talked about using the TCP protocol to connect to a server because we just said up where we were talking about the parts of the URL that “HTTP” is the protocol. That’s because TCP is the internet protocol used to connect two computers over the internet while HTTP is a web protocol used to exchange web data.
Without getting too much into how networking works, suffice it to say that HTTP is a set of procedures for exchanging web data, specifically, hypertext documents, hyperlinks, and other basic web features that are essentially synonymous with how we use the internet today but are in fact specific to the web.
Step 4: Connecting with HTTPS (i.e. HTTP using TLS/SSL)
Usually, when you connect to a website these days, you’re actually using HTTPS instead of just HTTP. This is, in fact, not a different protocol from HTTP, but HTTP with a layer of encryption on it. That is to say, that if you just use HTTP, web data is exchanged “in the clear,” or in other words, in a way that anyone and everyone could read. There’s nothing in particular about an internet or HTTP connection that’s direct or exclusive to the two endpoints of the connection. Remember, the internet and the web are distributed. That’s one of their strengths. And web data gets relayed, routed, and otherwise intercepted all along the circuitous path they often take to get from a server to your browser.
That’s where HTTPS comes in. HTTPS adds another protocol to the mix—TLS, or as it’s often better known, SSL—which is a process that can be used to make all the data sent and received between a web server and a web browser secret to everyone except them. TLS/SSL does this by encrypting the data, which means encoding the data using a secret cipher.
TLS/SSL uses public key encryption, which employs complicated mathematics such that both sides of the communication can encrypt data that the other can decrypt without ever having exchanged their ciphers with each other.
When you enter a URL in your browser and it uses “HTTPS” for the protocol, your browser and the server then also carryout the protocol for establishing a secure connection using TLS/SSL.
Step 5: Web content is received
Finally, once the TCP connection, HTTP connection, and HTTPS connection are all established, your browser will receive the data from the web server located at the address you entered. If that’s a webpage, that data will be in HTML (hypertext markup language) format, a data format specific to the web.
Then, if you click on any hyperlinks on the page, enter any information to send to the server (like if you fill out a sign-up form or enter payment information), this information is sent and received via HTTP.
On many websites, HTML documents also refer to specific resources outside of themselves to complete the page that you see when the webpage loads. One good example of this is the stylesheet, or CSS. This is a way to store all the information about colors, fonts, background images, etc. that might apply to all webpages on a particular website separately from the data for the specific webpages. This can help ensure uniformity across an entire website and it keeps HTML documents lean, since that data doesn’t have to be added to every HTML page on a website.
This will be a separate file stored on the same web server, and will require a separate HTTP request from your browser.
Client-side scripting
Code can also be sent in the HTML file to be executed by your browser.
JavaScript, which enables scripts to be sent to your computer and run in your browser to create effects or enable you to interact with elements on a webpage. Responsive webpages also change according to your browser window size, which in turn usually corresponds to your screen size (desktop, tablet, or phone).
These are applications that run in your browser on your computer and so they’re called web applications.
Server-side scripting
The other possibility for greater dynamism in a webpage is server-side scripting. This is where scripting languages like PHP for example, are run on the web server that produce different output depending on input from the web browser (or by extension the user).
In this case, when you enter a URL in your browser, you might be “running” script remotely on a server.
What happens when you enter a URL in your browser
Hopefully this guide to what happens when you enter a URL in your browser and how a URL works helps you to understand what happens “under the hood” of the websites you visit on a regular basis. But hopefully it also inspires you to dig in to making your own website or, if you’re already inspired, helps you to understand the pieces you’ll need to make a successful website.
If you’re ready to get going making your own URLs for people to enter into their browsers, you’ll need a domain name, some kind of web server (through web hosting), and a TLS/SSL certificate—at the very least.
Tagged in DNSNom de domaine