Browser Storage
Persist small device-local preferences safely with storage APIs and versioned data.
Web storage keeps string data in the browser. localStorage survives restarts; sessionStorage lasts for the current tab session. Neither is a database or a secure secret store.
Save versioned state
progress.js
const key = "arcbyte:progress:v1";
const state = { version: 1, lesson: "dom", percent: 64 };
try {
localStorage.setItem(key, JSON.stringify(state));
const saved = JSON.parse(localStorage.getItem(key) ?? "null");
if (saved?.version === 1) console.log(saved.lesson);
} catch (error) {
console.warn("Progress could not be stored", error);
}
Storage can be blocked, full, cleared, or corrupted. Keep the application functional without it and validate parsed shapes.
Choose the right storage
Use cookies when a small value must accompany HTTP requests, IndexedDB for larger structured offline data, and a trusted server when data must sync across devices.
Keep this
Store only small nonsecret device-local state, version the schema, handle failure, and provide a way to clear it.
Your place is saved on this device.