This guide explains how to configure and use the Progressive Web App features in Nova Rewards.
- Offline Support: App works without internet connection using cached data
- Service Worker: Caches assets and API responses for offline access
- Push Notifications: Receive updates about rewards and campaigns
- Background Sync: Automatically sync failed transactions when back online
- Install Prompt: Users can install the app on their device
- App Manifest: Native app-like experience on mobile devices
Push notifications require VAPID keys for authentication:
cd novaRewards/backend
npm install web-push --save
npx web-push generate-vapid-keysCopy the generated keys to your .env file:
VAPID_PUBLIC_KEY=your-generated-public-key
VAPID_PRIVATE_KEY=your-generated-private-key
VAPID_EMAIL=admin@novarewards.com
NEXT_PUBLIC_VAPID_PUBLIC_KEY=your-generated-public-keyPlace app icons in novaRewards/frontend/public/icons/:
- icon-72x72.png
- icon-96x96.png
- icon-128x128.png
- icon-144x144.png
- icon-152x152.png
- icon-192x192.png
- icon-384x384.png
- icon-512x512.png
You can use tools like PWA Asset Generator to generate these from a single source image.
Add the notifications route to your backend server:
const notificationsRouter = require('./routes/notifications');
app.use('/api/notifications', notificationsRouter);- Build and run the app:
npm run build && npm start - Open DevTools > Application > Service Workers
- Verify the service worker is registered
- Open DevTools > Network
- Select "Offline" from the throttling dropdown
- Navigate the app - cached pages should load
- Go to Settings page
- Click "Enable Notifications"
- Grant permission when prompted
- Send a test notification from backend
- Open the app in Chrome/Edge
- Look for the install banner at the bottom
- Click "Install" to add to home screen
import { usePWA } from '../hooks/usePWA';
function MyComponent() {
const {
isOnline,
notificationPermission,
enableNotifications,
triggerBackgroundSync
} = usePWA();
// Check online status
if (!isOnline) {
return <p>You are offline</p>;
}
// Enable notifications
const handleEnable = async () => {
await enableNotifications();
};
// Trigger background sync
const handleSync = async () => {
await triggerBackgroundSync('sync-transactions');
};
}From your backend:
const axios = require('axios');
await axios.post('http://localhost:3001/api/notifications/send', {
userId: 'user-id',
title: 'New Reward Available!',
body: 'You earned 50 NOVA tokens',
url: '/rewards'
});- Chrome/Edge: Full support
- Firefox: Full support
- Safari: Partial support (no push notifications on iOS)
- Opera: Full support
- HTTPS Required: PWA features require HTTPS in production
- Database Storage: Replace in-memory subscription storage with database
- Icon Optimization: Compress icons for faster loading
- Cache Strategy: Adjust cache duration based on your needs
- Analytics: Track PWA install rates and offline usage
- Ensure you're running on localhost or HTTPS
- Check browser console for errors
- Clear browser cache and reload
- Verify VAPID keys are correctly set
- Check notification permissions in browser settings
- Ensure backend has web-push package installed
- Verify
/offlineroute exists - Check service worker cache configuration
- Test with DevTools offline mode