What happens between pressing Enter and seeing the page? This lesson follows the steps: the browser, the domain name server, the IP address, the web server and the HTML. Then it explains cookies, session and persistent, and what websites use them for.
about 30 min1 simulation1 practice question
Lesson 3 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
From a URL to a page on the screen
You type www.example.org/news.html and press Enter. Less than a second later, the page is on your screen. Let us slow that second down.
The browser has a problem. It knows the domain name, but computers on the internet find each other by IP address. So the first job is to turn the name into a number. That is the job of a domain name server (DNS). A DNS is a server that holds a list of domain names and the IP addresses that go with them. It works like the contacts list on a phone, where you find a number by a name.
Three boxes: the web browser at the bottom left, a domain name server (DNS) at the top, and the web server at the bottom right. Numbered arrows show the order. Arrow 1 goes from the browser to the DNS with the domain name. Arrow 2 goes from the DNS back to the browser with the IP address. Arrow 3 goes from the browser to the web server with a request. Arrow 4 goes from the web server back to the browser with the page in HTML. A note at the browser says that it renders the HTML.
Here are the steps, in order.
The user types the URL into the address bar of the web browser, or clicks a link.
The browser sends the domain name to a DNS.
The DNS looks up the domain name and finds the matching IP address. If it does not hold that name, it asks another DNS, and that one can ask another.
The DNS sends the IP address back to the browser. If no DNS knows the name, the browser shows an error.
The browser uses the IP address to send an HTTP or HTTPS request to the web server that holds the website.
The web server finds the page and sends it back to the browser as HTML, with its other files.
The browser renders the HTML and displays the page.
In an exam, name every part: the browser, the DNS, the IP address, the web server and the HTML. Say who sends what to whom.
Why the second visit is faster
A DNS keeps a copy of the answers it has received from other servers. So the next time someone asks for the same domain name, the first DNS already knows it. Fewer servers are asked, and the page arrives sooner.
Cookies
You put two books into a basket on a shopping website and move to another page. The basket still holds the books. How does the website remember? A web server does not remember you from one request to the next. A cookie does that job.
A cookie is a small text file. A website sends it, and the web browser stores it on the user's device. Each time the browser asks that website for a page, it sends the cookie back. So the website can recognise the user.
There are two kinds.
A session cookie is kept only while the browser is open. It is held in memory and deleted when the browser is closed. It is used, for example, to hold the items in a shopping basket during one visit.
A persistent cookie is saved in the device's storage. It stays after the browser is closed, until its expiry date or until the user deletes it. It is used to remember a user from one visit to the next.
Websites use cookies for these functions.
Saving personal details, such as a name or an address, so a form fills itself in.
Tracking user preferences, such as the language of the site or a dark colour scheme.
Holding items in an online shopping cart while the user goes on shopping.
Storing login details, so the user stays logged in.
Cookies can also record which pages a user visits, and some are used to choose the adverts a user sees. That is why many websites ask before they store cookies. You can delete cookies in the browser settings.
Practise with new numbers
Try it in Python
The program acts as two domain name servers. The first is asked first. If it does not know a name, the second one is asked, and the first one keeps the answer for next time. Look at the third lookup.
Common mistakes
Saying the DNS sends the web page. The DNS only sends the IP address. The web server sends the page.
Getting the order wrong. The DNS comes before the web server, because the browser needs the IP address first.
Saying cookies are programs. A cookie is a small text file. It cannot run.
Mixing up the two kinds of cookie. A session cookie goes when the browser closes. A persistent cookie stays until it expires or is deleted.
Remember these
The browser sends the domain name to a DNS, and the DNS returns the IP address.
The browser sends a request to the web server at that IP address. The server sends the HTML, and the browser renders it.
A DNS that does not know a name asks another DNS.
A cookie is a small text file that a website stores on the user's device through the browser. Session cookies last for one visit. Persistent cookies stay until they expire or are deleted.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
What does the domain name server send back to the browser?
Put these in order: the web server sends HTML; the DNS returns the IP address; the browser renders the page; the browser sends the domain name to the DNS.
On a first visit, 3 DNS servers are asked, each taking 15ms, and the web server takes 90ms. How long until the page arrives?
Lena closes her browser and opens it again. The website still knows her chosen language. Which kind of cookie did that?
Give two things that websites use cookies for.
Enroll free in The Internet, the Web and How Pages Reach You
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.