tts-voice-creator-clone-and.../static/sw.js
mARTin-B78 40e42590cc Release v1.6.0: a11y (WCAG AA), i18n (DE), PWA, perf, tests, Cast UX
Cast: card/list views, sort & filter, online voice picker, "Hear a line"
sample button, AI character notes, import auto-save.

Platform: WCAG 2.1 AA accessibility pass; German UI translation + language
picker; installable PWA with offline shell; GZip + content-visibility
virtualization + lazy images + Rehearser PCM memory cap (mobile stability);
Playwright suite (desktop + iPhone); opt-in minified bundle build.

Fixes: screenplay parser false characters; Fish-Speech inline-tag tones;
narrator/voice pickers list full library; clone GUI rework; fish.audio
import dedup; voice-ID rename; bulk-delete modal.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-03 14:23:35 +02:00

39 lines
1.4 KiB
JavaScript

/* TTS Voice Creator — network-first service worker.
Always tries the network first (so live edits/new versions show immediately) and
only falls back to cache when offline. Never touches the API or cross-origin
requests, so it can't serve stale data or break audio/streaming. */
const CACHE = 'tts-vc-v1';
self.addEventListener('install', () => self.skipWaiting());
self.addEventListener('activate', (e) => {
e.waitUntil((async () => {
const keys = await caches.keys();
await Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)));
await self.clients.claim();
})());
});
self.addEventListener('fetch', (e) => {
const req = e.request;
if (req.method !== 'GET') return;
const url = new URL(req.url);
if (url.origin !== self.location.origin) return; // ignore CDN / cross-origin
if (url.pathname.startsWith('/api/')) return; // never cache the API
e.respondWith((async () => {
try {
const net = await fetch(req);
// Cache only successful static shell assets for offline fallback
if (net && net.ok && (url.pathname === '/' || url.pathname.startsWith('/static/'))) {
const c = await caches.open(CACHE);
c.put(req, net.clone());
}
return net;
} catch (err) {
const cached = await caches.match(req);
if (cached) return cached;
throw err;
}
})());
});