Choose and observe storage
Choose storage from the job
Match cookies, Web Storage, IndexedDB, Cache Storage, and OPFS to the shape and destination of the data.
8 minute lesson
Choose the smallest API that fits the real job. Small does not mean familiar.
Use a cookie when the browser must send a small value with matching HTTP requests. Use localStorage for a small string preference. Use sessionStorage for a small tab-scoped value. Use IndexedDB for structured records, Cache Storage for request and response pairs, and OPFS for origin-private files.
Do not put a large client-only object in a cookie. It adds bytes to matching requests. Do not put hundreds of notes in localStorage. Its synchronous calls block JavaScript, and every value is a string.
The field-notes app will use several APIs on purpose. Combining tools is normal when each stored value has a clear owner and cleanup rule.
Choose an API for a theme, authentication session, one-tab draft, searchable offline notes, cached manual, and large attachment. Reject one tempting but wrong alternative for every choice.
Lesson completed