How do you implement progressive web applications for cross-platform deployment?
Progressive Web Apps (PWAs) deliver app-like experiences through web technologies. Core features: Service Workers (background scripts that enable offline functionality, push notifications, and background sync), Web App Manifest (JSON file defining app name, icons, theme color, display mode, and start URL), and HTTPS (required for Service Worker registration). Implementation: start with a responsive web application, add a manifest.json file for installability, implement a Service Worker for offline caching and background functionality, and optimize for performance (target Lighthouse PWA score of 100). Caching strategies: cache-first (serve from cache, fall back to network, ideal for static assets), network-first (try network, fall back to cache, ideal for dynamic content), stale-while-revalidate (serve from cache immediately, update cache from network in background, best user experience for frequently updated content), and cache-only (for fully offline resources). Offline functionality: cache critical application shell (HTML, CSS, JS) for instant loading, implement IndexedDB for local data storage, queue user actions during offline and sync when connectivity returns (Background Sync API), and provide clear UI indicators for offline state and pending sync. Push notifications: implement via Push API and Service Worker, request user permission contextually (not on first visit), send relevant and timely notifications, and provide notification management settings. Installation: modern browsers prompt installation when PWA criteria are met (manifest, Service Worker, HTTPS), implement a custom install prompt using the beforeinstallprompt event for better timing and conversion. Performance: implement code splitting and lazy loading, use Workbox for Service Worker management (Google's library with pre-built caching strategies), optimize images with responsive formats (WebP, AVIF), and implement precaching for critical resources.