5.6 KiB
5.6 KiB
PWA Setup Guide
✅ Implemented Features
1. Service Worker
- Caching Strategy: Aggressive prefetch for app shell
- API Caching: Freshness strategy with 1-hour cache (max 100 requests)
- Image Caching: Performance strategy with 7-day cache (max 50 images)
- Configuration:
ngsw-config.json
2. Web App Manifests
- Dexar:
public/manifest.webmanifest(purple theme #a855f7) - Novo:
public/manifest.novo.webmanifest(green theme #10b981) - Features:
- Installable on mobile/desktop
- Standalone display mode
- 8 icon sizes (72px to 512px)
- Russian language metadata
3. Offline Support
- App shell loads instantly from cache
- API responses cached for 1 hour
- Product images cached for 7 days
- Automatic background updates
🚀 Testing PWA Functionality
Local Testing with Production Build
# Build for production
npm run build -- --configuration=production
# Serve the production build
npx http-server dist/dexarmarket -p 4200 -c-1
# For Novo brand
npx http-server dist/novomarket -p 4201 -c-1
Chrome DevTools Testing
- Open
http://localhost:4200 - Open DevTools (F12)
- Go to Application tab
- Check:
- Service Workers: Should show registered worker
- Cache Storage: Should show
ngsw:/:db,ngsw:/:assets - Manifest: Should show app details
Install Prompt Testing
- Open app in Chrome/Edge
- Click the install icon in address bar (➕)
- Confirm installation
- App opens as standalone window
- Check Start Menu/Home Screen for app icon
Offline Testing
- Open app while online
- Navigate through pages (loads assets)
- Open DevTools → Network → Toggle Offline
- Refresh page - should still work!
- Navigate to cached pages - should load instantly
📱 Mobile Testing
Android Chrome
- Open app URL
- Chrome shows "Add to Home Screen" banner
- Install and open - works like native app
- Splash screen with your logo/colors
iOS Safari
- Open app URL
- Tap Share → "Add to Home Screen"
- Icon appears on home screen
- Opens in full-screen mode
🔧 Configuration Details
Service Worker Caching Strategy
{
"app": {
"installMode": "prefetch", // Download immediately
"updateMode": "prefetch" // Auto-update in background
},
"assets": {
"installMode": "lazy", // Load on-demand
"updateMode": "prefetch"
},
"api-cache": {
"strategy": "freshness", // Network first, fallback to cache
"maxAge": "1h" // Keep for 1 hour
},
"product-images": {
"strategy": "performance", // Cache first, update in background
"maxAge": "7d" // Keep for 7 days
}
}
Manifest Differences
| Property | Dexar | Novo |
|---|---|---|
| Theme Color | #a855f7 (purple) | #10b981 (green) |
| Name | Dexar Market | Novo Market |
| Icons | Default Angular | Default Angular |
| Background | White (#ffffff) | White (#ffffff) |
🎨 Custom Icons (Recommended)
Replace the default Angular icons with brand-specific ones:
public/icons/
├── icon-72x72.png # Smallest (splash screen)
├── icon-96x96.png
├── icon-128x128.png
├── icon-144x144.png
├── icon-152x152.png # iOS home screen
├── icon-192x192.png # Android home screen
├── icon-384x384.png
└── icon-512x512.png # Largest (splash, install prompt)
Design Guidelines:
- Use solid background color (purple for Dexar, green for Novo)
- Center white logo/icon
- Keep design simple (shows at small sizes)
- Export as PNG with transparency or solid background
🔄 Update Strategy
How Updates Work
- User visits app
- Service worker checks for updates
- New version downloads in background
- User refreshes → gets updated version
- Old cache automatically cleared
Force Update (Development)
# Clear all caches
chrome://serviceworker-internals/ # Unregister worker
chrome://settings/clearBrowserData # Clear cache
# Or in code (add to app.config.ts)
navigator.serviceWorker.getRegistrations().then(registrations => {
registrations.forEach(reg => reg.unregister());
});
📊 Performance Benefits
Before PWA
- Initial load: ~2-3s (network dependent)
- Subsequent loads: ~1-2s
- Offline: ❌ Not available
After PWA
- Initial load: ~2-3s (first visit)
- Subsequent loads: ~200-500ms (cached)
- Offline: ✅ Fully functional
- Install: ✅ Native app experience
🐛 Troubleshooting
Service Worker Not Registering
- Check console for errors
- Ensure HTTPS (or localhost)
- Clear browser cache and reload
Old Version Not Updating
- Hard refresh:
Ctrl+Shift+R(Windows) orCmd+Shift+R(Mac) - Unregister worker in DevTools
- Wait 24 hours (automatic update)
Manifest Not Loading
- Check
index.htmlhas<link rel="manifest"> - Verify manifest path is correct
- Check manifest JSON is valid (no syntax errors)
Icons Not Showing
- Check icon paths in manifest
- Ensure icons exist in
public/icons/ - Verify icon sizes match manifest
📚 Next Steps
- Custom Icons: Create brand-specific icons for both themes
- Push Notifications: Add user engagement (requires backend)
- Background Sync: Queue offline orders, sync when online
- Analytics: Track PWA installs, offline usage
- A2HS Prompt: Show custom "Install App" banner