Bitpath

Lesson 1 · Unit 04

Storage

Cookies and their attributes, localStorage, sessionStorage, and what travels with a request

13 exercisesabout 3 min

What you practise

  • Cookies and their attributes (HttpOnly, Secure, SameSite), localStorage and sessionStorage, IndexedDB in outline, what is sent with each request

Try a question from this lesson

Pick one

A site keeps a session id in a cookie and a colour theme in localStorage. The page then loads an image from the same site. What travels with that image request?

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

Cookies

A server sets a cookie with a Set-Cookie response header. The browser stores it and sends it back in a Cookie header with every later request to that site.

That is how a server recognises you from one request to the next. Attributes after the value limit who can see the cookie and when.

response   Set-Cookie: sid=a1b2; HttpOnly
request    Cookie: sid=a1b2

Concept

Web storage

Script on a page can keep data in the browser without any cookie.

localStorage holds strings for one origin and stays until it is cleared. sessionStorage is the same but belongs to a single tab. IndexedDB is a real database for large or structured data.

None of it is ever sent to a server.

localStorage.setItem("theme", "dark");
localStorage.getItem("theme");  // "dark"
localStorage.getItem("nope");   // null

10 more exercises in the app

  • 1× fill the blanks
  • 4× type the answer
  • 3× multiple choice
  • 1× match the pairs
  • 1× true or false

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy