PWA & Offline
Progressive Web App Features
Section titled “Progressive Web App Features”What Makes This a PWA?
Section titled “What Makes This a PWA?”- Installable: Can be installed on Android devices as a standalone app
- Offline-capable: Works with cached data when no connection available
- Fast: Service worker caching makes subsequent loads instant
- Reliable: Never shows “no connection” page when data is cached
- Engaging: App-like experience with smooth transitions
Manifest Configuration
Section titled “Manifest Configuration”- Name: JP Portal (JIIT Student Portal)
- Short Name: JP Portal
- Theme Color:
#000000(black) - Background Color:
#000000 - Display:
standalone(hides browser UI) - Start URL:
/ - Icons: Multiple sizes (72x72 to 512x512) in
public/pwa-icons/
Service Worker Architecture
Section titled “Service Worker Architecture”Configuration
Section titled “Configuration”Configured via vite-plugin-pwa in vite.config.js with Workbox strategies.
Precaching
Section titled “Precaching”Assets precached during service worker installation:
- Pyodide Core: WASM files and data files from CDN
- Python Wheels:
jiit_marksandPyMuPDFfrompublic/artifact/ - Static Assets: App icons, manifest, critical files
- App Shell: HTML, CSS, JavaScript bundles
Runtime Caching Strategies
Section titled “Runtime Caching Strategies”1. CacheFirst (Offline-first)
Section titled “1. CacheFirst (Offline-first)”Used for: Pyodide files, Python wheels, static images
// Returns cached version if available, otherwise fetches// Ideal for assets that rarely changeBenefits:
- Instant load times
- Works offline
- Reduces bandwidth
2. StaleWhileRevalidate
Section titled “2. StaleWhileRevalidate”Used for: JavaScript bundles, CSS files, API responses, PDFs
// Returns cached version immediately// Updates cache in background for next timeBenefits:
- Fast response times
- Always up-to-date eventually
- Good for frequently changing content
3. NetworkFirst
Section titled “3. NetworkFirst”Used for: HTML documents, navigation requests
// Tries network first, falls back to cache on failureBenefits:
- Always fresh when online
- Offline fallback available
Cache Expiration
Section titled “Cache Expiration”- Images: 50 entries max, 30 days TTL
- Pyodide: No expiration (long-term cache)
- API Data: Managed by localStorage (see below)
Local Storage Cache System
Section titled “Local Storage Cache System”Implementation
Section titled “Implementation”Comprehensive caching system in cache.js with TypeScript-like interfaces.
Cache Key Structure
Section titled “Cache Key Structure”// User-specific data with semester contextattendance-{username}-{semesterId}subjects-{username}-{semesterId}grades-{username}-{semesterId}examSchedule-{username}-{semesterId}
// Subject-specific datasubject-{subjectCode}-{username}-{semesterId}subject-attendance-{subjectCode}-{username}-{semesterId}subject-choices-{username}-{semesterId}
// Semester metadatasemesters-{username}attendance-semesters-{username}subject-semesters-{username}
// Global user dataprofile-{username}hostel-{username}
// App statecgpaCalculatorSemesterscgpaCalculatorSgpaSubjectscgpaCalculatorTargetCgpadefaultThemedefaultTabattendanceGoalswipeEnableddefaultMessMenuViewCache Entry Format
Section titled “Cache Entry Format”{ data: any, // The actual cached data timestamp: number, // When cached (Date.now()) expiry: number, // TTL in milliseconds version: string // Cache version for migrations}Cache Functions
Section titled “Cache Functions”Getters
Section titled “Getters”getAttendanceFromCache(username, semesterId)getSubjectDataFromCache(username, semesterId)getGradesFromCache(username, semesterId)getExamScheduleFromCache(username, semesterId)getProfileFromCache(username)// ... and many moreSetters
Section titled “Setters”saveAttendanceToCache(username, semesterId, data, expiry)saveSubjectDataToCache(username, semesterId, data, expiry)saveGradesToCache(username, semesterId, data, expiry)// ... corresponding settersManagement
Section titled “Management”clearExpiredCache() // Remove expired entries onlyclearAllCache() // Remove all cached dataclearSpecificCache(dataType) // Remove specific data typegetCacheStats() // Get cache size and entry countCache Expiration
Section titled “Cache Expiration”- Default TTL: 24 hours (86400000 ms)
- Configurable: Can be set per-cache-call
- Automatic Cleanup: Checked on cache reads
- Manual Cleanup: Via Settings dialog
Offline Mode
Section titled “Offline Mode”Activation Conditions
Section titled “Activation Conditions”Offline mode activates when:
- Login fails (network error or wrong credentials)
- AND cached data exists for the user
- App automatically switches to
ArtificialWebPortal
ArtificialWebPortal
Section titled “ArtificialWebPortal”Mimics the online WebPortal API using cached data:
class ArtificialWebPortal { async get_attendance_meta() // Returns cached semester list async get_attendance(semester) // Returns cached attendance async get_sgpa_cgpa() // Returns cached grades async get_registered_subjects() // Returns cached subjects async get_personal_info() // Returns cached profile async get_exam_schedule() // Returns cached exam data // ... other methods}Offline Indicator
Section titled “Offline Indicator”- Yellow badge in header: “Offline” with refresh icon
- Clicking badge reloads page (attempts reconnection)
- Visible only when using
ArtificialWebPortal
Feature Restrictions
Section titled “Feature Restrictions”When offline, restricted features:
- Fee Submission: Requires live connection
- Feedback Submission: Requires API
- Data Refresh: Uses cached data only
- Timetable Generation: May fail if external service unavailable
Available features:
- Attendance: Full functionality with cached data
- Grades: View cached grades and SGPA/CGPA
- Subjects: View registered subjects
- Profile: View personal information
- Exams: View cached exam schedule
- Academic Calendar: Works (static JSON file)
- CGPA Calculator: Full functionality (localStorage-based)
Installation Guide
Section titled “Installation Guide”Android Installation
Section titled “Android Installation”- Open app in Chrome or supported browser
- Look for install button in navbar (download icon)
- Click install button or use browser menu “Add to Home Screen”
- App icon appears on home screen
- Opens in standalone mode (no browser UI)
iOS (Limited PWA Support)
Section titled “iOS (Limited PWA Support)”- iOS Safari has limited PWA support
- Can add to home screen via Share menu
- No install prompt available
- Service worker support varies by iOS version
Desktop Installation
Section titled “Desktop Installation”- Chrome, Edge: Install button in address bar
- Creates desktop shortcut
- Opens in app window
Testing Offline Functionality
Section titled “Testing Offline Functionality”Method 1: Browser DevTools
Section titled “Method 1: Browser DevTools”- Open app and log in
- Navigate through all features to warm caches:
- Visit Attendance, Grades, Exams, Subjects, Profile
- View subject details to cache individual subjects
- Check at least 2-3 subjects to ensure good coverage
- Open Chrome DevTools (F12)
- Go to Network tab
- Select “Offline” from throttling dropdown
- Reload page (Ctrl+R)
- App should load with offline indicator
- Navigate features - should work with cached data
Method 2: Airplane Mode
Section titled “Method 2: Airplane Mode”- Warm caches as above
- Enable airplane mode on device
- Open app (or reload if already open)
- Should work with offline indicator
Method 3: Service Worker Test
Section titled “Method 3: Service Worker Test”- Visit
chrome://serviceworker-internals/ - Find JP Portal service worker
- Click “Stop” to simulate service worker failure
- Reload page
- Service worker restarts and app works
Verification Checklist
Section titled “Verification Checklist”- Offline badge appears in header
- Can view attendance with cached data
- Can view grades for cached semesters
- Can view profile information
- Subject details load from cache
- Academic calendar works (static data)
- Theme toggle works
- CGPA calculator works
- No error messages about network
- Smooth navigation between routes
Cache Management
Section titled “Cache Management”Via Settings Dialog
Section titled “Via Settings Dialog”- Click settings icon in header
- Go to “Cache” tab
- View cache statistics (size, entry count)
- Options:
- Clear Expired: Removes only expired entries
- Clear All: Removes all cached data (requires confirmation)
- Clear Specific: Remove data by type (attendance, grades, etc.)
Programmatic Management
Section titled “Programmatic Management”import { clearExpiredCache, clearAllCache, clearSpecificCache, getCacheStats} from '@/components/scripts/cache'
// Clear expired entriesclearExpiredCache()
// Clear all cacheclearAllCache()
// Clear specific dataclearSpecificCache('attendance')clearSpecificCache('grades')
// Get cache infoconst stats = getCacheStats()console.log(`Cache size: ${stats.size} bytes`)console.log(`Entries: ${stats.count}`)When to Clear Cache
Section titled “When to Clear Cache”- Data appears stale or outdated
- Experiencing unusual behavior
- After semester change (to fetch new data)
- Before important operations (fee, feedback)
- When storage quota exceeded
Performance Optimization
Section titled “Performance Optimization”Cache-First Loading
Section titled “Cache-First Loading”- Component mounts
- Check cache for data
- Display cached data immediately (if available)
- Fetch fresh data in background
- Update UI when fresh data arrives
- Update cache with fresh data
Smart Prefetching
Section titled “Smart Prefetching”- Attendance page prefetches subject list
- Grades page prefetches semester metadata
- Profile page prefetches hostel info
- Reduces perceived load time
Background Sync (Future)
Section titled “Background Sync (Future)”- Planned: Queue failed requests for retry
- Auto-submit when connection restored
- Useful for feedback, fee payments
Troubleshooting
Section titled “Troubleshooting”App Won’t Work Offline
Section titled “App Won’t Work Offline”- Check if you visited pages while online first
- Clear browser cache and reload while online
- Check localStorage not disabled in browser
- Verify service worker registered (DevTools → Application → Service Workers)
Stale Data Showing
Section titled “Stale Data Showing”- Pull down to refresh (if implemented)
- Use refresh button in settings
- Clear cache and reload
Service Worker Not Registering
Section titled “Service Worker Not Registering”- Check HTTPS (required for service workers)
- Check browser compatibility
- Clear browser data and retry
- Check console for registration errors
Storage Quota Exceeded
Section titled “Storage Quota Exceeded”- Clear old cached data
- Reduce cache size in settings
- Browser may auto-evict least-used data
- Check browser storage settings