Lesson 1 · Unit 04
Storage
Cookies and their attributes, localStorage, sessionStorage, and what travels with a request
What you practise
- Cookies and their attributes (
HttpOnly,Secure,SameSite),localStorageandsessionStorage, 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?
Correct answer
The cookie only
Why
Cookies were made for the server: the browser attaches them to every request to that site, images included. localStorage is for the page: only script can read it, and nothing in it is ever sent by the browser.
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=a1b2Concept
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"); // null10 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.