Spaces:
Paused
Paused
Download sw.js from DillonLD/VoiceStudio: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/spaces/DillonLD/VoiceStudio/resolve/main/sw.js
- Command line
-
hf download hf://spaces/DillonLD/VoiceStudio/sw.js
-
curl -L -o sw.js https://huggingface.co/spaces/DillonLD/VoiceStudio/resolve/main/sw.js
1.37 kB
| const CACHE_NAME = "voice-studio-shell-v2"; | |
| const APP_SHELL = ["/", "/mobile", "/manifest.webmanifest", "/mobile-manifest.webmanifest", "/icon.svg"]; | |
| self.addEventListener("install", (event) => { | |
| event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL))); | |
| self.skipWaiting(); | |
| }); | |
| self.addEventListener("activate", (event) => { | |
| event.waitUntil( | |
| caches.keys().then((names) => Promise.all( | |
| names.filter((name) => name.startsWith("voice-studio-shell-") && name !== CACHE_NAME) | |
| .map((name) => caches.delete(name)) | |
| )) | |
| ); | |
| self.clients.claim(); | |
| }); | |
| self.addEventListener("fetch", (event) => { | |
| const request = event.request; | |
| const url = new URL(request.url); | |
| if (request.method !== "GET" || url.origin !== self.location.origin || | |
| url.pathname.startsWith("/api/") || url.pathname.startsWith("/files/")) return; | |
| if (request.mode === "navigate") { | |
| event.respondWith(fetch(request).then((response) => { | |
| const copy = response.clone(); | |
| caches.open(CACHE_NAME).then((cache) => cache.put(request, copy)); | |
| return response; | |
| }).catch(async () => (await caches.match(request)) || caches.match(url.pathname.startsWith("/mobile") ? "/mobile" : "/"))); | |
| return; | |
| } | |
| event.respondWith(caches.match(request).then((cached) => cached || fetch(request))); | |
| }); | |