Files
jeremy bayseandClaude Sonnet 5 5352f39887 Make SuiviCPT an installable PWA
Adds what iOS/Android need to treat the site as an installable app
from Safari's "Add to Home Screen": a manifest.json, apple-touch-icon
set generated from the existing logo mark (scripts/generate-icons.mjs,
sharp as a dev dependency), and the apple-mobile-web-app-* meta tags
iOS Safari requires since it ignores manifest.json entirely.

The service worker is deliberately minimal — this app shows live
financial data, so navigations always hit the network first. It only
caches enough to serve offline.html when there's no connection, not a
full offline-first app shell.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-03 11:03:37 +02:00

34 lines
1.0 KiB
JavaScript

// Minimal service worker: exists only to satisfy PWA installability criteria
// and give a usable offline fallback. Deliberately not a full offline-first
// cache — this app shows live financial data, so navigations always go to
// the network first; only the built Vite assets and the offline page are
// cached, never HTML page content.
const CACHE = 'suivicpt-shell-v1';
const OFFLINE_URL = '/offline.html';
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open(CACHE).then((cache) => cache.add(OFFLINE_URL))
);
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((key) => key !== CACHE).map((key) => caches.delete(key)))
)
);
self.clients.claim();
});
self.addEventListener('fetch', (event) => {
if (event.request.mode !== 'navigate') {
return;
}
event.respondWith(
fetch(event.request).catch(() => caches.match(OFFLINE_URL))
);
});