Lesson 0005 · ~12 minutes · synthesis
One skill: given a feature brief, write a complete file-storage choice — store, tree shape, I/O path, and one risk you own.
This is the durable skill from MISSION.md: defend an OPFS choice (or rejection) in a design review without hand-waving.
You can complete this from lessons 1–4 alone. External web.dev/MDN reads remain optional enrichment, not a gate.
Run in order. Earlier gates reject more options than later ones.
What must live on the client? Memory if re-fetch is fine. Web Storage only for tiny strings. Cache Storage for HTTP shell/assets. IndexedDB for structured entities. OPFS for file-shaped private bytes. User-visible pickers for real disk paths. Server for multi-device truth. (Lessons 1, 4)
getDirectory root; folder layout you invent;
getFileHandle /
getDirectoryHandle (+ create);
remove / removeEntry; list with
async iteration. Private origin tree — not Finder. (Lesson
2)
Default: createWritable → write → close;
read via getFile. High-throughput / Wasm / random
bytes: dedicated worker +
createSyncAccessHandle (exclusive lock, buffers,
flush/close). (Lesson
3)
Wrong tool, private vs UVFS, quota/eviction/persist, Safari hostility, multi-tab locks, main-thread thrash, unbounded growth, sync/re-hydrate policy. (Lesson 4)
“We use OPFS | IndexedDB | Cache | pickers | memory | server because job; tree is folder layout + handles; I/O is writable streams | worker sync access; we own quota / lock / re-hydrate / privacy-vs-UVFS.”
Keep the print playbook open after this course — compressed form of all five lessons.
Pick the best default package. Equal-length options.
Podcast app: store multi-MB episode audio offline as files; a worker streams bytes without re-downloading. Same-origin SPA.
Notes app: multi-KB rich drafts offline, filter by project, reopen days later same browser. Sync may lag.
Design tool must open a project from a path the user picks and save back to that real disk location (Finder/Explorer).
Product embeds SQLite-wasm; needs a durable on-device DB file with high-throughput random access for large local datasets.
Stakeholder pitch: “OPFS holds the only copy of user projects forever, across phones, and never needs a server backup.”
When you want the deferred primaries: Storage for the web, The origin private file system, Persistent storage, MDN FileSystemSyncAccessHandle.