Chapter 9 · Offline Support
Interview drill
5 questions from this chapter. Answer each one out loud first, then open it to compare.
-
9.1"You deployed a fix but users still see the broken version. Why?"
- The old service worker keeps control until every tab using it closes; a refresh doesn't replace it.
- Either call
skipWaitingandclients.claim, or surface an explicit update prompt — silence is what causes this. - It's also why a kill-switch SW and cache versioning are mandatory before your first production deploy.
-
9.2"When would you build a PWA instead of a native app?"
- When reach and update speed matter more than deep device integration — content, commerce, tools, internal apps.
- When install friction is the main funnel problem: a link that becomes an app beats a store listing.
- Not when you need background location, tight OS integration, or store-based discovery and billing.
-
9.3"The user taps Send twice on a flaky connection. How do you avoid a duplicate message?"
- The client creates the message ID once, before the first attempt, and every retry reuses it as the idempotency key.
- The server records keys it has already applied and returns the stored result for a repeat instead of applying it again.
- The UI renders from the local outbox by that same ID, so the screen shows one message too — clock, then tick.
-
9.4"Two devices edit the same note offline. What happens when both reconnect?"
- Each edit carries the version it was based on, so the second to arrive is visibly stale — a conflict, not a silent overwrite.
- Fields that don't overlap merge automatically; for the same field, choose per field — last write wins for low stakes, the user decides for content that matters.
- For genuinely collaborative text, use a CRDT so concurrent edits always converge and there is nothing to resolve.
-
9.5"Your offline notes app loses users' unsent notes on iPhone. Why, and what do you do?"
- Safari has no Background Sync, so the queue only flushes while the app is open — and if the site isn't installed, its storage can be cleared after 7 days of Safari use without the user interacting with it.
- Flush on open, on
onlineand on visibility change; encourage Add to Home Screen, and callpersist()after the first offline save. - Show unsent items clearly so nothing disappears silently, and keep the outbox small by collapsing edits (9.3).