PWA Integration - chintan992/letsstream2 GitHub Wiki
This guide covers the Progressive Web App (PWA) features in Let's Stream V2.0 and how to work with them.
Let's Stream V2.0 is built as a Progressive Web App, offering:
- Offline functionality
- Installation capability
- Push notifications
- Background sync
- App-like experience
// Configuration in vite.config.ts
VitePWA({
registerType: 'prompt',
includeAssets: [
'favicon.ico',
'apple-icon-180.png',
'manifest-icon-192.maskable.png',
'manifest-icon-512.maskable.png'
],
manifest: {
name: "Let's Stream V2.0",
short_name: "Let's Stream",
description: "Watch movies and TV shows online",
theme_color: '#3b82f6',
start_url: '/',
display: 'standalone',
background_color: '#0f0f0f'
}
})- Cache management
- API request caching
- Offline content serving
- Push notification handling
- Background sync
// Example: PWA install prompt component
const PWAInstallPrompt = () => {
const [showPrompt, setShowPrompt] = useState(false);
useEffect(() => {
// Listen for beforeinstallprompt
window.addEventListener('beforeinstallprompt', (e) => {
e.preventDefault();
setShowPrompt(true);
});
}, []);
return showPrompt ? (
<div className="pwa-prompt">
<h3>Install App</h3>
<p>Install Let's Stream for a better experience!</p>
<button onClick={handleInstall}>Install</button>
</div>
) : null;
};- Used for dynamic content
- Fallback to cache
- Regular cache updates
- Configurable timeouts
- Static assets
- Images and icons
- CSS and JavaScript
- Fonts and media
- Cached media metadata
- User preferences
- Watch history
- UI components
// Example: Offline status hook
const useOfflineStatus = () => {
const [isOffline, setIsOffline] = useState(!navigator.onLine);
useEffect(() => {
const handleOnline = () => setIsOffline(false);
const handleOffline = () => setIsOffline(true);
window.addEventListener('online', handleOnline);
window.addEventListener('offline', handleOffline);
return () => {
window.removeEventListener('online', handleOnline);
window.removeEventListener('offline', handleOffline);
};
}, []);
return isOffline;
};- Generate VAPID keys
- Configure Firebase Cloud Messaging
- Request user permission
- Handle push events
// Example: Push notification registration
const registerPushNotifications = async () => {
try {
const permission = await Notification.requestPermission();
if (permission === 'granted') {
const token = await getMessagingToken();
await saveUserToken(token);
}
} catch (error) {
console.error('Error registering push notifications:', error);
}
};// Example: Register background sync
const registerSync = async () => {
if ('serviceWorker' in navigator && 'SyncManager' in window) {
const registration = await navigator.serviceWorker.ready;
try {
await registration.sync.register('syncUserData');
} catch (error) {
console.error('Background sync failed:', error);
}
}
};- Watch history sync
- User preferences sync
- Offline actions queue
- Failed request retry
-
Lazy Loading
- Route-based code splitting
- Image lazy loading
- Component lazy loading
-
Asset Optimization
- Image compression
- Font subsetting
- CSS optimization
-
Data Protection
- Secure storage
- Token management
- offline data encryption
-
Update Management
- Version control
- Cache invalidation
- Update notification
- Manifest validation
- Service worker registration
- Offline functionality
- Install prompt
- Push notifications
- Background sync
-
Lighthouse
- PWA score
- Performance metrics
- Best practices
-
Chrome DevTools
- Application tab
- Service worker debugging
- Cache inspection
-
Service Worker
- Registration failures
- Update issues
- Cache problems
-
Installation
- Prompt not showing
- Installation failures
- Update issues
-
Offline Mode
- Cache misses
- Sync failures
- Data persistence issues
// Example: Service worker debugging
if (process.env.NODE_ENV === 'development') {
window.addEventListener('sw-state-change', (e) => {
console.log('Service Worker state:', e.detail);
});
navigator.serviceWorker.addEventListener('message', (event) => {
console.log('Message from Service Worker:', event.data);
});
}- Lighthouse
- Chrome DevTools
- PWA Builder
- Firebase Console