10LOC

#service-worker

Chrome APIsadvanced

Periodic Background Sync for resilient refresh jobs

type PeriodicSyncRegistration = ServiceWorkerRegistration & {
  periodicSync: { register: (tag: string, options: { minInterval: number }) => Promise<void> };
};

export const schedulePeriodicRefresh = async (tag: string, minIntervalMs: number): Promise<boolean> => {

Schedule light refresh work that can survive transient network loss.

Chrome APIsintermediate

Background Sync for offline-friendly actions

type SyncRegistration = ServiceWorkerRegistration & { sync: { register: (tag: string) => Promise<void> } };

export const scheduleOfflineAction = async (tag: string, replayNow: () => Promise<void>): Promise<void> => {
  const registration = await navigator.serviceWorker.ready;
  const canBackgroundSync = "sync" in registration;

Replay user actions later when connectivity returns with Background Sync.

Web Platformadvanced

A minimal cache-first offline service worker

const CACHE_NAME = "app-shell-v1";
const PRECACHE_URLS = ["/", "/styles.css", "/app.js", "/offline.html"];

self.addEventListener("install", (event) => {
  (event as Event & { waitUntil: (p: Promise<unknown>) => void }).waitUntil(

Precache the app shell on install and serve every request from cache first, falling back to the network only on a cache miss.