Pwa Offline First
Installation
SKILL.md
2.2.2 Pwa Offline First
This skill defines the technical standards for building Progressive Web Apps that work reliably regardless of network conditions, install natively on devices, and pass all Lighthouse PWA audits.
1. Web App Manifest (manifest.json)
Goal: Ensure installability and native-like presentation on all platforms.
- Required Fields:
name,short_name,start_url,display(set tostandalone),background_color,theme_color,icons(at minimum 192×192 and 512×512 PNG, includemaskablepurpose variant). - Optional Enhancements:
description,categories,screenshots(for richer install UI on Android),shortcuts(app launcher shortcuts),share_target(to receive shared content). - Scope: Set
scopeto/or the app's root path. Ensurestart_urlfalls within the declared scope. - Validation: Test with Chrome DevTools → Application → Manifest panel. Verify installability criteria are met.
2. Service Worker Lifecycle
Goal: Reliable caching and seamless updates without stale content.
- Registration: Register the service worker in the app's entry point with
navigator.serviceWorker.register('/sw.js', { scope: '/' }). Wrap in a feature check. - Install Event: Pre-cache the App Shell (HTML, CSS, JS, critical fonts, icons) during the
installevent. Usecache.addAll()with a versioned cache name (e.g.,app-shell-v2). - Activate Event: Clean up old caches by iterating
caches.keys()and deleting any cache name that doesn't match the current version. Callclients.claim()to immediately take control. - Update Strategy: Use
skipWaiting()cautiously. Prefer prompting the user with a "New version available — Refresh" banner triggered by thecontrollerchangeevent or a Broadcast Channel message from the new SW.