Lessons in this course (16)

12. Storage, fetch, CORS and browser APIs

IntermediateMediumLesson 12 of 16
StorageCapacityLifetimeSent to server
Cookies~4 KBExpiry dateYes, with every request
localStorage~5–10 MBUntil clearedNo
sessionStorage~5 MBTab sessionNo
IndexedDBLarge (quota-based)Until clearedNo — async, structured data
Cache APILargeUntil clearedNo — service workers/PWA

Never store auth tokens in localStorage if you can avoid it (readable by any XSS); prefer HttpOnly; Secure; SameSite cookies or a BFF.

Other APIs: fetch, AbortController, IntersectionObserver (lazy load, infinite scroll), ResizeObserver, MutationObserver, Web Workers, Service Workers (offline/PWA), WebSockets, history.pushState (SPA routing), Clipboard, Geolocation, Notifications.

CORS — the browser blocks reading cross-origin responses unless the server sends Access-Control-Allow-Origin; preflight OPTIONS for non-simple requests. It's fixed on the server, not in JS.