This document provides comprehensive setup and testing instructions for the FarmCredit PWA implementation.
FarmCredit is now a fully functional Progressive Web App (PWA) with:
- ✅ Service worker for offline caching
- ✅ Web app manifest with icons
- ✅ Offline fallback page
- ✅ Install prompt on supported browsers
- ✅ Push notification setup (optional)
- ✅ Network status indicator
- ✅ Responsive design (mobile/tablet/desktop)
- ✅ WCAG 2.1 AA accessibility compliance
- ✅ TypeScript strict mode (no
anytypes)
npm install next-pwa @ducanh2912/next-pwa workbox-window
npm install -D @types/serviceworker sharpOr if using pnpm:
pnpm add next-pwa @ducanh2912/next-pwa workbox-window
pnpm add -D @types/serviceworker sharpPlace a source icon (minimum 512x512px) at public/icon-source.png, then run:
npm run generate-iconsThis will generate all required icon sizes (72x72 to 512x512) in public/icons/.
Add the following screenshots for better app store presentation:
public/screenshots/desktop-1.png(1280x720)public/screenshots/mobile-1.png(750x1334)
Create a .env.local file:
NEXT_PUBLIC_VAPID_PUBLIC_KEY=your_vapid_public_key_here
VAPID_PRIVATE_KEY=your_vapid_private_key_hereGenerate VAPID keys using:
npx web-push generate-vapid-keysstellar-app-os/
├── app/
│ ├── api/
│ │ └── health/
│ │ └── route.ts # Health check endpoint
│ ├── offline/
│ │ └── page.tsx # Offline fallback page
│ └── layout.tsx # Updated with PWA metadata
├── components/
│ ├── atoms/
│ │ ├── InstallPrompt.tsx # Install prompt component
│ │ └── NetworkStatus.tsx # Network status indicator
│ └── providers/
│ └── PWAProvider.tsx # PWA initialization provider
├── lib/
│ ├── pwa.ts # Service worker utilities
│ └── notifications.ts # Push notification utilities
├── public/
│ ├── icons/ # PWA icons (generated)
│ ├── screenshots/ # App screenshots
│ ├── manifest.json # Web app manifest
│ └── sw.js # Service worker
├── scripts/
│ └── generate-icons.js # Icon generation script
└── next.config.ts # Updated with PWA headers
The service worker implements a multi-strategy caching approach:
- Precache: Essential assets cached on install (
/,/offline, manifest, icons) - Cache First: Static assets (JS, CSS, images, fonts)
- Network First: API calls with cache fallback
- Offline Fallback: Custom offline page for navigation requests
The app displays a native install prompt on supported browsers:
- Appears automatically when PWA criteria are met
- Can be dismissed (won't show again for 7 days)
- Styled with Stellar brand colors
- Fully accessible with keyboard navigation
When offline:
- Cached pages continue to work
- API responses served from cache when available
- Custom offline page displays for uncached routes
- Network status indicator shows connection state
To enable push notifications:
- Generate VAPID keys and add to
.env.local - Call
requestNotificationPermission()to request permission - Call
subscribeToPushNotifications()to subscribe - Send notifications from your backend using the subscription
Example usage:
import { requestNotificationPermission, subscribeToPushNotifications } from '@/lib/notifications';
// Request permission
const permission = await requestNotificationPermission();
if (permission === 'granted') {
// Subscribe to push notifications
const subscription = await subscribeToPushNotifications();
// Send subscription to your backend
}The app automatically detects and displays network status changes:
- Shows "Back Online" badge when connection restored
- Shows "Offline Mode" badge when connection lost
- Auto-hides after 5 seconds
- Accessible with proper ARIA labels
- Build the production version:
npm run build
npm start-
Open http://localhost:3000 in your browser
-
Test offline functionality:
- Open DevTools → Application → Service Workers
- Check "Offline" checkbox
- Navigate the app to verify offline support
- Deploy to a server with HTTPS (required for PWA)
- Open the site in Chrome
- Tap the install prompt or menu → "Install app"
- Test offline by enabling airplane mode
- Deploy to a server with HTTPS
- Open the site in Safari
- Tap Share → "Add to Home Screen"
- Test offline by enabling airplane mode
Run a Lighthouse audit to verify PWA compliance:
- Open DevTools → Lighthouse
- Select "Progressive Web App" category
- Click "Generate report"
- Verify all PWA checks pass
Expected results:
- ✅ Installable
- ✅ PWA optimized
- ✅ Works offline
- ✅ Configured for a custom splash screen
- ✅ Sets a theme color
- ✅ Content sized correctly for viewport
- ✅ Has a
<meta name="viewport">tag - ✅ Provides a valid apple-touch-icon
All PWA components follow WCAG 2.1 AA guidelines:
- Semantic HTML elements
- Proper ARIA labels and roles
- Keyboard navigation support
- Sufficient color contrast (tested with Stellar colors)
- Focus indicators
- Screen reader announcements for status changes
-
Keyboard navigation:
- Tab through install prompt
- Press Enter/Space to activate buttons
- Press Escape to dismiss (if implemented)
-
Screen reader:
- Test with NVDA (Windows) or VoiceOver (Mac/iOS)
- Verify all interactive elements are announced
- Check status updates are announced (aria-live)
-
Color contrast:
- Use DevTools → Lighthouse → Accessibility
- Verify all text meets WCAG AA standards (4.5:1 for normal text)
- Push to GitHub
- Import project in Vercel
- Add environment variables (if using push notifications)
- Deploy
Vercel automatically serves the service worker and manifest with correct headers.
Ensure your hosting platform:
- Serves the site over HTTPS
- Serves
/sw.jswithCache-Control: public, max-age=0, must-revalidate - Serves
/manifest.jsonwith proper MIME type (application/manifest+json) - Doesn't block service worker registration
- Check browser console for errors
- Verify HTTPS is enabled (required for PWA)
- Check DevTools → Application → Service Workers
- Clear cache and hard reload (Ctrl+Shift+R)
- Verify all PWA criteria are met (run Lighthouse audit)
- Check if app is already installed
- Clear site data and revisit
- Some browsers require user engagement before showing prompt
- Verify service worker is active (DevTools → Application)
- Check cache storage (DevTools → Application → Cache Storage)
- Ensure assets are being cached (check Network tab)
- Try clearing cache and re-caching
- Verify icons exist in
public/icons/ - Check manifest.json paths are correct
- Clear browser cache
- Verify icon sizes match manifest specifications
The PWA implementation includes several performance optimizations:
- Precaching of critical assets
- Runtime caching of API responses
- Efficient cache invalidation
- Background sync for offline actions
- Lazy loading of non-critical components
Expected Lighthouse scores:
- Performance: 90+
- Accessibility: 100
- Best Practices: 100
- SEO: 100
- PWA: 100
| Browser | Install | Offline | Push Notifications |
|---|---|---|---|
| Chrome (Android) | ✅ | ✅ | ✅ |
| Chrome (Desktop) | ✅ | ✅ | ✅ |
| Safari (iOS) | ✅ | ✅ | ❌ |
| Safari (macOS) | ✅ | ✅ | ❌ |
| Edge | ✅ | ✅ | ✅ |
| Firefox | ✅ | ✅ | ✅ |
When you update the service worker:
- Increment the cache version in
public/sw.js:
const CACHE_NAME = 'farmcredit-v2'; // Increment version- The service worker will automatically update on next visit
- Users will be prompted to reload for the new version
Update the PRECACHE_ASSETS array in public/sw.js:
const PRECACHE_ASSETS = [
'/',
'/offline',
'/new-route', // Add new route
'/manifest.json',
'/icons/icon-192x192.png',
'/icons/icon-512x512.png',
];- Service workers only work over HTTPS (except localhost)
- Push notifications require user permission
- Cached data is stored locally and can be cleared by user
- No sensitive data should be cached
- Implement proper authentication for API endpoints
For issues or questions:
- Check this documentation
- Review browser console for errors
- Run Lighthouse audit for diagnostics
- Open an issue on GitHub with details