LambdaLabTM
Computer Networks · Class 12 · Web Browsers
networksweb browsers⏱️ 7 min read

CookiesOptional for Computer Science

🎬 This chapter has a 12:38 video: Web Services →

A website has no memory. Every request that arrives looks like the first one it has ever seen — and yet a shopping site remembers what is in your basket, and a school portal keeps you logged in. The trick is that the site does not remember you. Your browser does, and reminds it.

1What a cookie is

Cookie
A cookie is a small text file that a website asks your browser to store on your computer. On every later visit to that site, the browser sends the cookie back with the request, so the website can recognise the browser and pick up where it left off.

Two things in that definition are exam answers on their own. A cookie is stored on your computer, not on the website’s server. And it is a text file — plain words and values, which cannot run and is not a program.

A cookie, from both sides

The browser window is what you see. The box below it is the small file the website asked your browser to keep.

Timetable
sunriseschool.example/timetable
Press “Visit for the first time”.
🍪 Cookies kept by the browser for sunriseschool.example

Nothing yet — the site has not been visited.

A cookie is stored by the browser, on your computer — one small text file per website.

2What cookies are used for

Used forWhat it means for you
Staying logged inYou type your password once, not on every page
Remembering a shopping basketItems are still there when you come back
PreferencesLanguage, dark mode, font size stay as you set them
Counting visitorsThe site can tell a returning visitor from a new one
AdvertisingBuilding a record of the sites you visit, to target ads

The cloakroom token

You hand in your bag and get a numbered token. The cloakroom does not remember your face — the token in your pocket is what reunites you with your bag. The token is useless anywhere else, and if you throw it away, the cloakroom no longer knows which bag was yours. A cookie is that token, kept by your browser.

3Kinds of cookie

Session and persistent
A session cookie is deleted when you close the browser — it lasts one sitting, like the basket on a shopping site. A persistent cookie has an expiry date written into it and survives until then, which is how a site keeps you logged in for weeks.
First-party and third-party
A first-party cookie is set by the site you are actually on. A third-party cookie is set by another company whose advertisement or button is embedded in that page — and because the same company’s ads appear on thousands of sites, it can follow you across all of them. That is why browsers now block third-party cookies by default.

4The privacy question

A cookie cannot read your files, cannot carry a virus and cannot run a program — it is text. What it can do is build a record of where you have been, which is a privacy problem rather than a security one.

What to do about it
Block third-party cookies in the browser’s privacy settings, clear cookies on a shared computer, and use a private window when you do not want a visit remembered. Blocking all cookies works, but then no site can keep you logged in.

5From the board papers

1
With reference to browsing websites, briefly explain the term cookie. Also mention any two points of significance of it.CBSE board exam 2023 (compartment)
2 marks
▶Show the answer

A cookie is a small text file that a website stores on the visitor’s computer through the browser, and which the browser sends back on every later visit to that site.

Two points of significance:

  • It lets the website recognise a returning visitor, so a user can stay logged in and a shopping basket is not lost.
  • It stores the user’s preferences — language, theme, settings — so the site opens the way the user left it.
2
Explain the concept of browser cookies and mention one advantage of using them.CBSE sample paper 2024–25
2 marks
▶Show the answer

Browser cookies are small text files that a website asks the browser to save on the user’s computer, holding a little data such as a user name, a session number or a preference. The browser sends them back to the same website on later visits.

Advantage: browsing becomes faster and easier — the user does not have to log in or set their preferences again on every visit.

3
Assertion (A): Internet cookies are text files that contain small pieces of data, like a username, password and user’s preferences while surfing the Internet.
Reason (R): To make browsing the Internet faster and easier, it is required to store certain information on the server’s computer.CBSE sample paper 2022–23
1 mark
▶Show the answer

A is true, R is false. The assertion is the correct definition of a cookie. The reason is wrong in one word: the information is stored on the user’s computer by the browser, not on the server’s computer. That one word is the whole question.

Where cookies are allowed, blocked or cleared is in the browser’s own settings — see Browser Settings.

6Check yourself

Quick Check

Where is a cookie stored?

Quick Check

Riya's shopping basket empties every time she closes the browser, but she stays logged in for weeks. Which two cookies are at work?

Quick Check

Which statement about cookies is TRUE?