Skip to content
Draft
326 changes: 326 additions & 0 deletions DEPLOYMENT_GUIDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,326 @@
# Deployment Guide - AngryRaphi PWA Optimizations

## Quick Start

To deploy the optimized PWA version:

```bash
./deploy.sh
```

The deployment script will automatically:
1. Clean previous builds
2. Install dependencies
3. Run code analysis
4. Build with all optimizations
5. Deploy to Firebase Hosting

## What's Been Optimized

### 🎯 Key Improvements
- **85% reduction** in image sizes (5.1MB saved)
- **Enhanced service worker** with smart caching
- **Firebase hosting** optimized with cache headers
- **Build configuration** with maximum optimization (O4)
- **Loading experience** improved with faster transitions

### 📊 Expected Results
- First load: 40-60% faster
- Repeat visits: 70-90% faster
- Lighthouse Performance: 85-95+
- PWA Score: 95-100

## Pre-Deployment Checklist

Before running `./deploy.sh`, verify:

- [ ] Flutter SDK is installed and up to date
- [ ] Firebase CLI is installed (`npm install -g firebase-tools`)
- [ ] You're logged into Firebase (`firebase login`)
- [ ] You're in the project root directory
- [ ] All changes are committed to git

## Deployment Steps

### 1. Verify Current Setup

```bash
# Check Flutter version
flutter --version

# Check Firebase login
firebase login --no-localhost

# Verify Firebase project
firebase projects:list
```

### 2. Run Deployment Script

```bash
# Make script executable (if needed)
chmod +x deploy.sh

# Deploy
./deploy.sh
```

### 3. Monitor Deployment

The script will show progress for each step:
- ✅ Cleaning previous build
- ✅ Getting dependencies
- ✅ Analyzing code
- ✅ Building web app (this takes a few minutes)
- ✅ Deploying to Firebase

### 4. Verify Deployment

After successful deployment, the script will show:
```
🎉 Deployment completed successfully!
App is live at: https://angryraphi.web.app
```

## Post-Deployment Verification

### Immediate Checks (5 minutes)

1. **Open the app in browser**
```
https://angryraphi.web.app
```

2. **Check Browser Console**
- Open DevTools (F12)
- Look for errors in Console tab
- Verify service worker registration

3. **Verify Service Worker**
- DevTools → Application → Service Workers
- Should see "angryraphi-cache-v2.3.0"
- Status should be "activated and running"

4. **Check Cache Storage**
- DevTools → Application → Cache Storage
- Should see two caches:
- angryraphi-cache-v2.3.0
- angryraphi-runtime-v2.3.0

5. **Verify Image Sizes**
- DevTools → Network tab
- Disable cache
- Reload page
- Check Icon-192.png size: should be ~152KB (not 1.1MB)

### Performance Testing (10 minutes)

1. **Run Lighthouse Audit**
```bash
# Using Chrome DevTools
F12 → Lighthouse → Generate Report

# Or using CLI
lighthouse https://angryraphi.web.app --view
```

Expected scores:
- Performance: 85-95+
- PWA: 95-100
- Best Practices: 90+
- Accessibility: (unchanged)
- SEO: (unchanged)

2. **Test Loading Times**
- DevTools → Network tab
- Set throttling to "Fast 3G"
- Hard reload (Ctrl+Shift+R)
- Measure total load time (should be < 5s)
- Reload again (should be < 1s from cache)

3. **Test Offline Mode**
- Load app with network on
- DevTools → Network → Check "Offline"
- Reload page
- App should load from cache (Firebase data won't load)

### Cache Header Verification (5 minutes)

Check that cache headers are correctly set:

```bash
# Test image caching (should be 1 year)
curl -I https://angryraphi.web.app/icons/Icon-192.png | grep -i cache-control

# Test HTML caching (should be no-cache)
curl -I https://angryraphi.web.app/ | grep -i cache-control

# Test manifest caching (should be 24 hours)
curl -I https://angryraphi.web.app/manifest.json | grep -i cache-control
```

Expected outputs:
- Images: `cache-control: public, max-age=31536000, immutable`
- HTML: `cache-control: public, max-age=0, must-revalidate`
- Manifest: `cache-control: public, max-age=86400`

## Monitoring After Deployment

### First 24 Hours

1. **Firebase Hosting Dashboard**
- Go to Firebase Console → Hosting
- Monitor traffic and bandwidth
- Check for 404 errors

2. **Firebase Performance Monitoring**
- Go to Firebase Console → Performance
- Monitor page load times
- Check for issues on different devices/networks

3. **User Feedback**
- Monitor support channels
- Check for reports of issues
- Verify offline functionality works

### First Week

1. **Analytics**
- Check page load times in Firebase Analytics
- Monitor PWA install events
- Track user engagement metrics

2. **Error Monitoring**
- Check Firebase Crashlytics (if enabled)
- Monitor browser console errors via monitoring tools
- Check service worker errors

3. **Performance Trends**
- Compare load times before/after
- Check bounce rate changes
- Monitor user session duration

## Rollback Plan

If issues are discovered after deployment:

### Option 1: Rollback in Firebase Console

1. Go to Firebase Console → Hosting
2. Click "Release history"
3. Find previous version
4. Click "..." menu → "Rollback"

### Option 2: Redeploy Previous Version

```bash
# Checkout previous version
git checkout <previous-commit-hash>

# Deploy
./deploy.sh

# Return to current branch
git checkout main
```

### Option 3: Quick Fix and Redeploy

```bash
# Fix the issue in code
# ... make changes ...

# Commit fix
git add .
git commit -m "Fix: <description>"

# Deploy
./deploy.sh
```

## Troubleshooting

### Service Worker Not Updating

**Problem**: Users still see old version

**Solution**:
1. Check service worker version in code
2. Increment version number if needed
3. Redeploy
4. Users will get update on next visit

### Images Not Loading

**Problem**: 404 errors for images

**Solution**:
1. Verify images exist in build/web/icons/
2. Check file names match manifest.json
3. Verify Firebase hosting rules
4. Check browser console for paths

### Performance Not Improved

**Problem**: Lighthouse scores not as expected

**Solution**:
1. Clear all browser caches
2. Test in incognito mode
3. Run Lighthouse multiple times (scores vary)
4. Check Network tab for large resources
5. Verify service worker is caching properly

### Cache Not Working

**Problem**: Assets not being cached

**Solution**:
1. Check service worker registration in DevTools
2. Verify cache names in service worker code
3. Check Network tab → "Size" column (should show "service worker")
4. Clear all caches and reload

## Support Resources

- **Documentation**:
- PWA_OPTIMIZATION.md
- TESTING_PWA_OPTIMIZATIONS.md

- **Firebase**:
- Console: https://console.firebase.google.com
- Documentation: https://firebase.google.com/docs/hosting

- **Flutter Web**:
- Documentation: https://flutter.dev/docs/get-started/web

- **Testing Tools**:
- Lighthouse: Built into Chrome DevTools
- WebPageTest: https://www.webpagetest.org
- Firebase Performance: In Firebase Console

## Success Metrics

After 1 week, you should see:

✅ Lighthouse Performance score improved by 15-25 points
✅ Average page load time reduced by 40-60%
✅ Repeat visitor load time reduced by 70-90%
✅ Bandwidth usage reduced (fewer large asset transfers)
✅ PWA install rate increased (if measured)
✅ Bounce rate decreased (if measured)
✅ No increase in error rates

## Contact

For issues or questions:
1. Check documentation in this repository
2. Review Firebase Console logs
3. Check service worker logs in browser console
4. Create issue in GitHub repository

---

**Last Updated**: 2025-12-13
**Version**: 2.3.0
**Optimization Focus**: PWA Loading Performance
Loading