ca-grow-ops-manager/frontend/public/sw.js
fullsizemalt f51a1072fe
Some checks failed
Deploy to Production / deploy (push) Failing after 0s
Test / backend-test (push) Failing after 0s
Test / frontend-test (push) Failing after 0s
feat(pwa): Add PWA support for installable kiosk app
- Added manifest.json for 'Add to Home Screen' installation
- Added service worker for offline caching
- Added app icons (192px, 512px)
- Updated index.html with mobile meta tags
- Created spec for Escort Handoff Mode (009)
2025-12-11 16:13:50 -08:00

55 lines
1.5 KiB
JavaScript

const CACHE_NAME = 'wolfpack-kiosk-v1';
const STATIC_ASSETS = [
'/kiosk',
'/badges',
'/manifest.json'
];
// Install event - cache static assets
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => {
return cache.addAll(STATIC_ASSETS);
})
);
self.skipWaiting();
});
// Activate event - clean up old caches
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames
.filter((name) => name !== CACHE_NAME)
.map((name) => caches.delete(name))
);
})
);
self.clients.claim();
});
// Fetch event - network first, falling back to cache
self.addEventListener('fetch', (event) => {
// Skip non-GET requests
if (event.request.method !== 'GET') return;
// Skip API requests (always fetch from network)
if (event.request.url.includes('/api/')) return;
event.respondWith(
fetch(event.request)
.then((response) => {
// Clone and cache the response
const responseClone = response.clone();
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, responseClone);
});
return response;
})
.catch(() => {
// Network failed, try cache
return caches.match(event.request);
})
);
});