Dev.Lib
arrow_backBack to Blogs
LEVEL_1010.7June 27, 20261 min read

Offline-first design

Frontend Architecture

Local source of truth syncs to server — optimistic UI, conflict resolution, queue mutations.

Summary

Local source of truth syncs to server — optimistic UI, conflict resolution, queue mutations. SW cache strategies (network-first vs cache-first) per resource type. UX for offline state honest (not fake online). Test flaky network not just airplane mode.

Code example

self.addEventListener('fetch', (event) => {
  if (event.request.mode === 'navigate') {
    event.respondWith(
      fetch(event.request).catch(() => caches.match('/offline.html')),
    );
    return;
  }
  event.respondWith(staleWhileRevalidate(event.request));
});

Key points

  • Local source of truth syncs to server — optimistic UI, conflict resolution, queue mutations.
  • SW cache strategies (network-first vs cache-first) per resource type.
  • UX for offline state honest (not fake online).
  • Test flaky network not just airplane mode.

Further reading

Related concepts