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 type | Strategy | Rationale |
|---|---|---|
| HTML (navigation) | networkFirst (3s timeout) → cache → /offline.html | Content freshness matters; cache only used when offline or slow |
Content JSON/markdown (/content/*) | networkFirst (3s timeout) → cache | Admin edits should appear immediately for online visitors |
CDN content (cdn.nortonshop.net/content/*) | networkFirst (3s timeout) → cache | Same rationale — dynamic content served via CDN |
Static assets (/static/*) | cacheFirst + background revalidation | Rarely change; versioned by VERSION bump |
| Cross-origin static (CDN images, fonts) | cacheFirst + background revalidation | Long-lived assets with stable URLs |
| POST / PUT / DELETE | network-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.
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.