PWA and Service Worker

The public site is a Progressive Web App. The service worker (sw.js) provides offline access and asset caching. A separate registration script (static/js/pwa-register.js) handles the update flow — detecting new versions, prompting the user, and sending SKIP_WAITING to activate the new worker.

Caching strategies

Request typeStrategyRationale
HTML (navigation)networkFirst (3s timeout) → cache → /offline.htmlContent freshness matters; cache only used when offline or slow
Content JSON/markdown (/content/*)networkFirst (3s timeout) → cacheAdmin edits should appear immediately for online visitors
CDN content (cdn.nortonshop.net/content/*)networkFirst (3s timeout) → cacheSame rationale — dynamic content served via CDN
Static assets (/static/*)cacheFirst + background revalidationRarely change; versioned by VERSION bump
Cross-origin static (CDN images, fonts)cacheFirst + background revalidationLong-lived assets with stable URLs
POST / PUT / DELETEnetwork-only (not intercepted)Never cache mutations

Version bumping

Both sw.js and pwa-register.js contain a VERSION constant (currently 1.0.6). When you change the service worker or precache list, bump this number in both files. The matching ?v=... query string in pwa-register.js forces the browser to treat the worker as new. On activation, old versioned caches are deleted automatically.

Always bump VERSION in both files together. If sw.js and pwa-register.js have different versions, browsers may not detect the update.

Push notifications

The service worker handles incoming push events and notification clicks. VAPID keys are stored in admin/.vapid-keys.json (auto-generated on first use). When a notification is tapped, the worker navigates to the target URL with a cache-bust timestamp (?_t=...) to ensure fresh content is shown even if the page was previously cached.

Precache list

The PRECACHE_URLS array in sw.js lists the app shell — the minimum set of files needed for the site to work offline. Pages not in this list still work offline after one online visit. Keep this list small; over-precaching slows install and wastes storage.

Dynamic cache cap

The dynamic cache (pages visited by the user) is LRU-capped at 60 entries. Oldest entries are evicted when the cap is exceeded.

Back to top