LifeMate — Personal, Family & Learning Companion

feat/aparat-learning-library
chore/phase1-repository-cleanup deploy/stable-web-apk deployment-static design/mobile-accessibility-v2 design/mobile-navigation-review docs/child-education-access-decision docs/offline-data-rescue-options docs/owner-guide-and-delivery-plan docs/phase1-policy-options docs/public-review-live-2026-10-15 feat/aparat-learning-library feat/child-device-safety feat/child-identity-schema feat/flutter-mobile-navigation feat/learning-content-operations feat/local-signing-preflight feat/online-family-stage0 feat/personal-encrypted-recovery feat/private-planner-series-api feat/public-review-page feat/standalone-weekly-planner feat/weekly-planner-android final-feature-1/iran-family-school fix/auth-abuse-expiry-safety fix/auth-expiry-after-lock fix/backend-request-safety fix/lifeguide-bootstrap-naming-ci fix/lifeguide-pages-qa-base-preflight fix/lifeguide-qa-pages-env-deployment fix/local-task-persistence fix/managed-child-session-boundary fix/personal-jalali-dates fix/personal-notification-controls fix/personal-upgrade-delivery-guard fix/sms-approval-gates fix/study-duration-display infra/cloudflare-neon-migration infra/lifeguide-cloudflare-qa infra/lifeguide-github-pages-qa infra/lifeguide-supabase-qa main phase-1/foundation-completion phase-2/product-foundation-identity phase-3/planner-school-family-core phase-4/ai-learning-wellbeing phase-5/hardening-observability-release test/android-reminder-acceptance test/personal-notification-settings test/personal-recovery-acceptance test/role-entry-apk
js 36 lines 1.41 KB
Raw
1 // Fresh application code/settings always come from the network. Cache only
2 // public static resources; no API, authentication, navigation or personal data.
3 const CACHE = 'lifeguide-static-v0.5.0-3';
4 const BASE_PATH = new URL('.', self.location.href).pathname;
5 const STATIC_PATH = /^(?:assets|canvaskit|icons)\//;
6 self.addEventListener('install', () => self.skipWaiting());
7 self.addEventListener('activate', (event) => {
8 event.waitUntil((async () => {
9 for (const key of await caches.keys()) {
10 if ((key.startsWith('lifeguide-static-') && key !== CACHE) || key.startsWith('flutter-')) {
11 await caches.delete(key);
12 }
13 }
14 await self.clients.claim();
15 })());
16 });
17 self.addEventListener('fetch', (event) => {
18 const request = event.request;
19 const url = new URL(request.url);
20 if (request.method !== 'GET' || url.origin !== self.location.origin ||
21 url.search || request.headers.has('authorization') ||
22 !url.pathname.startsWith(BASE_PATH) ||
23 !STATIC_PATH.test(url.pathname.slice(BASE_PATH.length))) return;
24 event.respondWith((async () => {
25 const cache = await caches.open(CACHE);
26 try {
27 const response = await fetch(request, {cache: 'no-store'});
28 if (response.ok) await cache.put(request, response.clone());
29 return response;
30 } catch (error) {
31 const stored = await cache.match(request);
32 if (stored) return stored;
33 throw error;
34 }
35 })());
36 });