This document explains the PWA (Progressive Web App) implementation for Stellar MicroPay, enabling:
- ✅ Installation on mobile home screens (Android & iOS)
- ✅ Offline access to cached pages
- ✅ Install banner on supported browsers
- ✅ Standalone app experience
Web App Manifest that defines:
- App name: "Stellar MicroPay"
- Short name: "MicroPay"
- Display mode: standalone (hides browser UI)
- Theme color: #7B3FE4 (Stellar purple)
- Icons: 192x192 and 512x512
Service Worker that handles:
- Caching of static assets (home page, dashboard, favicon, manifest)
- Network-first strategy with cache fallback
- Offline support for previously visited pages
- Cache versioning and cleanup
Custom Next.js document with:
- Manifest link tag
- Theme color meta tag
- Apple touch icon reference
- iOS-specific meta tags for web app capability
- MS Tile color for Windows
Added:
- Service worker registration on app load
InstallBannercomponent that:- Listens for
beforeinstallpromptevent - Shows a beautiful install prompt banner
- Allows users to install or dismiss
- Styled with Tailwind CSS to match app theme
- Listens for
SVG icons with:
- Stellar purple gradient background
- White diamond/stellar logo
- Rounded corners for modern app appearance
The manifest.json references PNG icons. You have two options:
-
Open
icon-192.svgin any browser -
Screenshot or use a tool to convert to PNG:
- Online: https://cloudconvert.com/svg-to-png
- Mac: Preview app → Export as PNG
- Windows: Paint or Photos app → Save as PNG
- CLI:
convert icon-192.svg icon-192.png(requires ImageMagick)
-
Save as:
public/icon-192.png(192x192 pixels)public/icon-512.png(512x512 pixels)
- Visit https://realfavicongenerator.net/ or https://pwacompat.com/
- Upload one of the SVG files
- Download generated icons
- Place in
frontend/public/directory
Design your own icons and save as:
public/icon-192.pngpublic/icon-512.png
cd frontend
npm run devNote: Service workers require HTTPS in production, but work on localhost for development.
- Deploy to HTTPS URL (e.g., Vercel, Netlify)
- Open in Chrome on Android
- Wait for install banner to appear OR
- Tap menu (⋮) → "Add to Home screen"
- App installs with splash screen and icon
- Deploy to HTTPS URL
- Open in Safari on iOS
- Tap Share button
- Scroll down → "Add to Home Screen"
- App adds to home screen
- Visit the app while online
- Navigate to home page and dashboard
- Go offline (Airplane mode or DevTools → Offline)
- Reload the page
- Cached version should load
- Open DevTools (F12)
- Go to Application tab
- Check:
- Manifest: View manifest details
- Service Workers: Check registration status
- Cache Storage: View cached assets
- Use Lighthouse tab → Generate PWA report
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| Install Banner | ✅ | ✅ | ❌ | ✅ |
| Service Worker | ✅ | ✅ | ✅ | ✅ |
| Offline Cache | ✅ | ✅ | ✅ | ✅ |
| Add to Home Screen | ✅ | ✅ | ✅ |
Note: iOS Safari doesn't support beforeinstallprompt event, so the install banner won't show. Users must manually add to home screen.
The service worker uses a network-first with cache fallback strategy:
- Try to fetch from network
- If successful, cache the response and return it
- If network fails, serve from cache
- For HTML pages, fallback to cached home page
This ensures:
- Users always get fresh content when online
- App works offline with last cached version
- Graceful degradation
The cache name includes a version number: micropay-v1
To update cached assets after deployments:
- Change
CACHE_NAMEinsw.js(e.g., tomicropay-v2) - Old cache will be automatically deleted on next load
- New assets will be cached
Edit in three places:
manifest.json→theme_color_document.tsx→<meta name="theme-color">_document.tsx→<meta name="msapplication-TileColor">
Edit sw.js → STATIC_ASSETS array:
const STATIC_ASSETS = [
'/',
'/dashboard',
'/transactions', // Add this
'/favicon.svg',
'/manifest.json',
];Edit the InstallBanner component in _app.tsx:
- Change colors, text, positioning
- Modify styling with Tailwind classes
- Add animations or custom behavior
- Must be served over HTTPS (except localhost)
- Manifest must have valid icons (PNG format)
- User must have interacted with the page
- On iOS, banner doesn't show (manual add only)
- Check browser console for errors
- Verify
sw.jsis accessible at/sw.js - Ensure browser supports service workers
- Check if blocked by browser settings
- Visit pages while online first to cache them
- Check Cache Storage in DevTools
- Verify service worker is active
- Clear cache and reload to reset
- Ensure PNG files exist in
public/folder - Check file names match manifest.json
- Verify image dimensions (192x192, 512x512)
- Use PNG format, not SVG
- Convert SVG icons to PNG format
- Test manifest.json is accessible at
/manifest.json - Verify service worker registers at
/sw.js - Test on Android Chrome (install & offline)
- Test on iOS Safari (add to home screen)
- Run Lighthouse PWA audit (aim for 100%)
- Update cache version after major updates
Consider adding:
- Background sync for offline transactions
- Push notifications
- More granular caching strategies
- App shortcuts in manifest
- Share target API
- Periodic background sync