PageSourceSearch

https://zappio.app.br/sw.js

js zappio.app.br collected 2026-10-02 01:17:27 UTC 2,465 bytes, 58 lines download raw bytes

1/* Service worker do Zappio (nuvem) — resiliência offline mínima.
2 *
3 * Objetivo: o DOMÍNIO abrir mesmo sem internet (casco do app em cache) para o
4 * componente de failover rodar e levar o aparelho ao nó local da loja.
5 *
6 * Estratégia conservadora:
7 *  - Navegações (HTML): network-first com fallback ao index.html em cache —
8 *    online sempre pega a versão nova (deploys não "grudam"); offline abre o casco.
9 *  - Assets estáticos do próprio domínio (/static, hasheados pelo build): cache-first
10 *    com preenchimento em runtime — imutáveis por nome, seguros de cachear.
11 *  - API/terceiros: NUNCA intercepta (passa direto) — dados sempre frescos.
12 */
13const CACHE = "zappio-shell-v1";
14
15self.addEventListener("install", (event) => {
16    event.waitUntil(caches.open(CACHE).then((c) => c.addAll(["/", "/index.html"]).catch(() => {})));
17    self.skipWaiting();
18});
19
20self.addEventListener("activate", (event) => {
21    event.waitUntil(
22        caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
23            .then(() => self.clients.claim())
24    );
25});
26
27self.addEventListener("fetch", (event) => {
28    const req = event.request;
29    if (req.method !== "GET") return;
30    const url = new URL(req.url);
31    if (url.origin !== self.location.origin) return;       // terceiros: não intercepta
32    if (url.pathname.startsWith("/api")) return;           // API: sempre rede
33
34    // Navegação (abrir/atualizar página): rede primeiro;
34 sem rede, casco do cache.
35    if (req.mode === "navigate") {
36        event.respondWith(
37            fetch(req).then((res) => {
38                const copy = res.clone();
39                caches.open(CACHE).then((c) => c.put("/index.html", copy)).catch(() => {});
40                return res;
41            }).catch(() => caches.match("/index.html").then((hit) => hit || Response.error()))
42        );
43        return;
44    }
45
46    // Assets do build (nomes hasheados) + ícones/manifest: cache-first com runtime fill.
47    if (url.pathname.startsWith("/static/") || /\.(js|css|png|svg|ico|woff2?)$/.test(url.pathname)) {
48        event.respondWith(
49            caches.match(req).then((hit) => hit || fetch(req).then((res) => {
50                if (res.ok) {
51                    const copy = res.clone();
52                    caches.open(CACHE).then((c) => c.put(req, copy)).catch(() => {});
53                }
54                return res;
55            }))
56        );
57    }
58});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.