Spaces:
Build error
PWA Implementation Guide for Open Notebook
What Was Implemented
Open Notebook has been successfully converted into a Progressive Web App (PWA) with the following features:
Features Added
Installable App
- Users can install Open Notebook to their home screen on mobile and desktop
- Works on iOS, Android, Windows, Mac, and Linux
- App appears in app launchers just like native apps
Offline Support
- Service worker caching for faster load times
- Graceful offline fallback page
- API caching with Network-First strategy (5-minute cache)
Smart Caching
- Static assets (JS, CSS, images) cached for 24 hours
- Google Fonts cached for optimal performance
- Next.js image optimization cached
Install Prompt
- Smart install prompt appears after 30 seconds
- Dismissible with 7-day cooldown
- Auto-detects if already installed
Mobile Optimized
- Apple Touch Icon support
- Proper viewport and theme-color meta tags
- App shortcuts for quick actions
Files Modified/Created
Modified Files
frontend/next.config.ts- PWA configuration with caching strategiesfrontend/src/app/layout.tsx- Added PWA meta tags and install promptfrontend/package.json- Added next-pwa dependency
New Files
frontend/public/manifest.json- Web app manifest with app metadatafrontend/public/offline.html- Offline fallback pagefrontend/src/components/common/InstallPWA.tsx- Install prompt componentfrontend/generate-icons.js- Icon generation scriptfrontend/public/icon-*.png- PWA icons (9 sizes)frontend/public/apple-touch-icon.png- iOS home screen icon
How to Test
1. Build and Start the App
cd /home/john/opennotebook/frontend
npm run build
npm start
Or with Docker:
cd /home/john/opennotebook
docker compose up --build
2. Test on Desktop (Chrome/Edge)
- Open Chrome/Edge browser
- Navigate to your Open Notebook URL (e.g.,
http://localhost:8502) - Look for the install icon in the address bar (⊕ or ⬇️)
- Click it and select "Install"
- The app will open in its own window
Alternative:
- Open DevTools (F12)
- Go to "Application" tab
- Click "Manifest" to verify manifest is loaded
- Check "Service Workers" to see if worker is active
- Use "Lighthouse" tab to run PWA audit
3. Test on Android
- Open Chrome browser on Android
- Navigate to your Open Notebook URL
- Wait 30 seconds for the install prompt to appear
- Or tap the menu (⋮) and select "Install app" or "Add to Home Screen"
- Tap "Install"
- Find the app icon on your home screen
Testing Tips:
- Use Chrome's Device Mode in DevTools to simulate mobile
- Remote debug using
chrome://inspecton desktop - Check console for any PWA-related errors
4. Test on iOS (Safari)
- Open Safari on iOS
- Navigate to your Open Notebook URL
- Tap the Share button (square with arrow)
- Scroll down and tap "Add to Home Screen"
- Customize name if desired and tap "Add"
- Find the app icon on your home screen
Note: iOS has limited PWA support:
- No automatic install prompt
- No background sync
- Limited push notification support
5. Test Offline Functionality
Desktop:
- Open DevTools (F12)
- Go to "Network" tab
- Check "Offline" checkbox
- Refresh the page
- You should see the offline fallback page
Mobile:
- Enable Airplane mode
- Open the installed app
- You should see cached content or offline page
6. Test PWA Features with Lighthouse
- Open Chrome DevTools (F12)
- Go to "Lighthouse" tab
- Select "Progressive Web App" category
- Click "Analyze page load"
- Review the PWA score (should be 90+)
PWA Configuration Details
Caching Strategies
| Resource Type | Strategy | Cache Duration | Notes |
|---|---|---|---|
| API Calls | NetworkFirst | 5 minutes | Falls back to cache if network is slow (10s timeout) |
| Static JS/CSS | StaleWhileRevalidate | 24 hours | Always serves from cache, updates in background |
| Images | StaleWhileRevalidate | 24 hours | Cached for fast loading |
| Google Fonts | CacheFirst (webfonts) / StaleWhileRevalidate (CSS) | 365 days / 7 days | Optimal font loading |
Manifest Features
- Display Mode: Standalone (looks like a native app)
- Orientation: Portrait-primary (mobile optimized)
- Theme Color: #000000 (customizable in manifest.json)
- Background Color: #ffffff (customizable in manifest.json)
- App Shortcuts: Quick access to New Notebook and Search
Customization
Change Theme Colors
Edit frontend/public/manifest.json:
{
"theme_color": "#667eea",
"background_color": "#ffffff"
}
Also update in frontend/src/app/layout.tsx:
<meta name="theme-color" content="#667eea" />
Adjust Install Prompt Timing
Edit frontend/src/components/common/InstallPWA.tsx:
// Change from 30 seconds (30000ms) to desired delay
setTimeout(() => {
setShowInstallPrompt(true);
}, 30000); // Change this value
Modify Caching Behavior
Edit frontend/next.config.ts in the runtimeCaching array:
- Change
handlertypes:NetworkFirst,CacheFirst,StaleWhileRevalidate - Adjust
maxAgeSecondsfor cache duration - Modify
maxEntriesfor cache size limits
Disable PWA in Development
PWA is automatically disabled in development mode. To enable it, edit next.config.ts:
disable: false, // Change from process.env.NODE_ENV === "development"
Troubleshooting
Install Button Not Showing
- Check if already installed (look for standalone display mode)
- PWA criteria not met - run Lighthouse audit
- HTTPS required (except localhost)
- Service worker may not be registered - check DevTools > Application > Service Workers
Service Worker Not Updating
- In DevTools > Application > Service Workers
- Check "Update on reload"
- Click "Unregister" and reload page
- Or use "Skip waiting" button
Icons Not Loading
- Verify icons exist:
ls frontend/public/icon-*.png - Regenerate if needed:
node frontend/generate-icons.js - Check manifest.json paths match icon filenames
- Clear cache and reinstall app
Manifest Not Found
- Check that manifest.json exists in
frontend/public/ - Verify build output includes public files
- Check browser console for 404 errors
- Ensure
manifest: "/manifest.json"in layout.tsx
App Not Working Offline
- Service worker must be active (check DevTools)
- Visit pages while online first to cache them
- API calls require cached responses or fallbacks
- Check offline.html is in public directory
Production Deployment
Important Considerations
HTTPS Required
- PWAs require HTTPS (except localhost)
- Ensure your production server has valid SSL certificate
Cache Updates
- Service worker updates automatically on new deployments
- Users get updates when they close and reopen the app
Environment Variables
NODE_ENV=productionenables PWA featuresAPI_URLmust be set correctly for your deployment
Docker Deployment
- PWA files are included in the standalone build
- Icons and manifest are served from the public directory
- No additional configuration needed
Next Steps
Optional Enhancements
Push Notifications
- Add web push notification support
- Requires backend integration for push subscriptions
Background Sync
- Queue API requests when offline
- Sync when connection is restored
Share Target API
- Allow sharing content to Open Notebook from other apps
- Add to manifest.json
App Shortcuts
- Already configured in manifest
- Can add more shortcuts for quick actions
Screenshots
- Add app screenshots to manifest
- Improves install prompt on some platforms
Resources
Support
For issues specific to Open Notebook PWA:
- Check browser console for errors
- Run Lighthouse audit for PWA compliance
- Verify service worker is active
- Test on different devices and browsers
Implementation Date: October 28, 2025 Implemented By: Claude Code Assistant Status: ✅ Complete and Ready for Testing