Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
4efbf4f
feat: implement Progressive Web App (PWA) functionality with offline …
SubhanRaj Dec 20, 2025
059be52
feat: Implement dark mode support and theme management
SubhanRaj Dec 20, 2025
49b9530
feat: Enhance dark mode styling for buttons and containers
SubhanRaj Dec 20, 2025
93cad77
feat: Add calendar with coin/payment SVG for subscription tracking
SubhanRaj Dec 20, 2025
f7f5dfb
feat: Update icons and manifest for improved PWA support
SubhanRaj Dec 20, 2025
153cafc
feat: Revamp PWA install banner and enhance offline page styling for …
SubhanRaj Dec 20, 2025
638d0ad
feat: Implement geolocation and auto-currency detection with UI updat…
SubhanRaj Dec 21, 2025
505dbbf
feat: Add location consent dialog and enhance currency detection flow
SubhanRaj Dec 21, 2025
66d9bf6
feat: Enhance PWA install banner with auto-hide functionality and imp…
SubhanRaj Dec 21, 2025
7ae8434
feat: Add clear all app data functionality and enhance currency detec…
SubhanRaj Dec 21, 2025
7841e63
feat: Refactor currency detection logic to prioritize manual settings…
SubhanRaj Dec 21, 2025
eae6d14
feat: Integrate SweetAlert2 for enhanced user notifications and confi…
SubhanRaj Dec 21, 2025
eb318e1
feat: Update cache version to v1.3.1 and enhance gradient styles for …
SubhanRaj Dec 21, 2025
f524bc7
feat: Synchronize selectedCurrency across app.js, geolocation.js, and…
SubhanRaj Dec 21, 2025
9ecd02f
feat: Update service worker cache version to v1.3.2 and remove consol…
SubhanRaj Dec 21, 2025
afc95a6
feat: Add search functionality for subscriptions with clear button an…
SubhanRaj Dec 23, 2025
7e9d084
feat: Implement search functionality for subscriptions with clear but…
SubhanRaj Dec 23, 2025
b3305d0
feat: Enhance clearAllSubs function with confirmation and success alerts
SubhanRaj Dec 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
240 changes: 240 additions & 0 deletions PWA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,240 @@
# PWA Implementation Guide

## Overview
SubGrid is now a fully functional Progressive Web App (PWA) with offline support, installation capabilities, and long-term device storage.

## Features Implemented

### ✅ Service Worker (sw.js)
- **Cache-first strategy** for static assets (HTML, CSS, JS, icons)
- **Network-first strategy** for exchange rate API calls
- **Offline fallback** to custom offline page when network unavailable
- **Automatic cache updates** with version management
- **Background sync** for exchange rates (when supported)
- **CDN resource caching** for Tailwind, Iconify, fonts

### ✅ Web App Manifest (manifest.json)
- App metadata (name, description, icons)
- Standalone display mode (feels like native app)
- Theme colors matching app design
- App shortcuts for quick actions
- Share target integration
- Multiple icon sizes (192x192, 512x512)

### ✅ Offline Support
- Custom offline page (offline.html) with:
- Connection status monitoring
- Auto-reload when online
- Clear messaging about offline capabilities
- Visual feedback
- All app functionality works offline (except exchange rate updates)

### ✅ Installation
- Install prompt banner at top of page
- Detects PWA installation capability
- One-click installation
- Apple iOS support with meta tags
- Android support with manifest

### ✅ Long-term Storage
- LocalStorage for subscription data (already implemented)
- Service worker caching for app shell
- Persistent across sessions and offline use
- Data survives browser restarts

## How to Use

### Testing Locally

1. **Serve with HTTPS** (required for service workers):
```bash
# Option 1: Using Python
python -m http.server 8000

# Option 2: Using npx
npx serve .

# Option 3: Using local-web-server
npx local-web-server --https
```

2. **Access via localhost**:
- Navigate to `http://localhost:8000`
- Open browser DevTools > Application tab
- Check "Service Workers" to see registration status
- Check "Manifest" to verify PWA configuration

3. **Test Offline**:
- Load the page once (caches resources)
- Go to DevTools > Network tab
- Check "Offline" mode
- Refresh page - should still work!
- Try adding subscriptions offline

4. **Test Installation**:
- Chrome: Look for install banner or + icon in address bar
- Edge: Similar to Chrome
- Safari iOS: Share > Add to Home Screen
- Android: Install banner appears automatically

### Deployment (Cloudflare Pages)

Already configured in `wrangler.jsonc`:

```bash
# Deploy to Cloudflare Pages
npx wrangler pages deploy .

# Or use Cloudflare dashboard
# - Connect your GitHub repo
# - Auto-deploys on push to main
```

### PWA Best Practices Implemented

✅ **HTTPS only** - Service workers require secure context
✅ **Responsive design** - Works on all screen sizes
✅ **Fast loading** - Cached assets load instantly
✅ **Works offline** - Core features available without network
✅ **Installable** - Meets all PWA criteria
✅ **App-like experience** - Standalone display mode
✅ **Theme colors** - Matches system/browser theme
✅ **Proper icons** - Multiple sizes for different devices

## File Structure

```
/
├── manifest.json # PWA manifest
├── sw.js # Service worker
├── offline.html # Offline fallback page
├── index.html # Main app (with PWA meta tags)
├── icons/
│ ├── icon-192.png # App icon (192x192)
│ ├── icon-512.png # App icon (512x512)
│ ├── icon-192.svg # Source SVG
│ └── icon-512.svg # Source SVG
└── screenshots/
└── README.md # Placeholder for app screenshots
```

## Caching Strategy

### Precached on Install
- `/` (home page)
- `/index.html`
- `/offline.html`
- `/styles.css`
- All JavaScript files
- App icons

### Cached on First Use
- CDN resources (Tailwind, Iconify, fonts)
- Exchange rate API responses

### Network First
- Exchange rate API (with cache fallback)

## Browser Support

| Feature | Chrome | Edge | Safari | Firefox |
|---------|--------|------|--------|---------|
| Service Worker | ✅ | ✅ | ✅ | ✅ |
| Web Manifest | ✅ | ✅ | ⚠️ * | ✅ |
| Installation | ✅ | ✅ | ⚠️ * | ❌ |
| Offline | ✅ | ✅ | ✅ | ✅ |
| Background Sync | ✅ | ✅ | ❌ | ❌ |

\* Safari uses Add to Home Screen instead of install prompts

## Debugging

### Chrome DevTools
1. Open DevTools (F12)
2. Go to **Application** tab
3. Check sections:
- **Manifest** - Verify manifest.json
- **Service Workers** - See registration & status
- **Cache Storage** - Inspect cached files
- **Local Storage** - View subscription data

### Common Issues

**Service worker not registering?**
- Must be served over HTTPS (or localhost)
- Check browser console for errors
- Verify sw.js path is correct

**Install prompt not showing?**
- Manifest must be valid
- Icons must be accessible
- App must be served over HTTPS
- User must visit site at least once

**Offline not working?**
- Service worker must be active
- Page must be cached
- Check Network tab in DevTools (set to Offline)

## Updating the PWA

When you make changes:

1. **Update cache version** in `sw.js`:
```javascript
const CACHE_VERSION = 'subgrid-v1.0.1'; // Increment version
```

2. **Service worker will auto-update**:
- Detects new version
- Shows reload prompt to user
- Cleans up old caches

## Performance Metrics

Expected Lighthouse scores (PWA audit):
- ✅ Progressive Web App: 100
- ✅ Performance: 95+
- ✅ Accessibility: 90+
- ✅ Best Practices: 100
- ✅ SEO: 100

## Future Enhancements

Consider adding:
- [ ] Push notifications for subscription renewals
- [ ] Background sync for data backup
- [ ] Periodic background sync for exchange rates
- [ ] Web Share API for sharing stats
- [ ] Payment Request API integration
- [ ] Device contacts API for split subscriptions
- [ ] IndexedDB for larger data sets
- [ ] Advanced caching strategies per route

## Security Considerations

✅ **No sensitive data in cache** - Only app shell
✅ **LocalStorage encryption** - Consider implementing
✅ **HTTPS required** - Enforced by service workers
✅ **Content Security Policy** - Consider adding headers
✅ **No external tracking** - Privacy-first approach

## Testing Checklist

- [ ] Service worker registers successfully
- [ ] App works offline after first visit
- [ ] Install prompt appears on supported browsers
- [ ] Installed app opens in standalone mode
- [ ] Icons appear correctly on home screen
- [ ] Offline page shows when network unavailable
- [ ] Cache updates on new deployment
- [ ] LocalStorage persists data
- [ ] Exchange rates update when online
- [ ] All visualizations work offline

## Resources

- [MDN: Progressive Web Apps](https://developer.mozilla.org/en-US/docs/Web/Progressive_web_apps)
- [Google: PWA Checklist](https://web.dev/pwa-checklist/)
- [Service Worker API](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API)
- [Web App Manifest](https://developer.mozilla.org/en-US/docs/Web/Manifest)
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,17 @@ A simple tool to visualize your subscription costs. See where your money goes ea
- Import subscriptions from bank statements (CSV)
- Export your visualization as an image
- Supports 38+ currencies
- **NEW: Progressive Web App (PWA)** - Install on your device, works offline!

## PWA Features

✨ **Install as an App** - Add to your home screen on mobile or desktop
📴 **Works Offline** - Access your subscription data without internet
⚡ **Fast Loading** - Cached assets load instantly
💾 **Long-term Storage** - Your data persists on your device
🔄 **Auto Updates** - Get the latest features automatically

See [PWA.md](PWA.md) for detailed PWA implementation documentation.

## How to use

Expand Down
Binary file added icons/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading