PageSourceSearch

https://rotamissoes.com.br/sw.js

js rotamissoes.com.br collected 2026-10-02 20:09:23 UTC 1,771 bytes, 59 lines download raw bytes

1const CACHE_NAME = 'rota-missoes-v2';
2const STATIC_ASSETS = ['/', '/index.html', '/manifest.json', '/rota-missoes.png'];
3
4self.addEventListener('install', (event) => {
5  event.waitUntil(
6    caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS))
7  );
8  self.skipWaiting();
9});
10
11self.addEventListener('activate', (event) => {
12  event.waitUntil(
13    caches.keys().then((keys) =>
14      Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
15    )
16  );
17  self.clients.claim();
18});
19
20self.addEventListener('fetch', (event) => {
21  const { request } = event;
22  if (request.method !== 'GET') return;
23
24  const url = new URL(request.url);
25  if (url.origin !== self.location.origin) return;
26
27  // APIs contêm conteúdo administrável. Nunca devolva uma cópia antiga do
28  // Service Worker: alterações de textos, SEO e imagens precisam aparecer
29  // assim que forem publicadas no painel.
30  if (url.pathname.startsWith('/api/')) {
31    event.respondWith(fetch(request, { cache: 'no-store' }));
32    return;
33  }
34
35  if (request.mode === 'navigate') {
36    event.respondWith(
37      fetch(request)
38        .then((response) => {
39          const copy = response.clone();
40          caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
41          return response;
42        })
43        .catch(() => caches.match(request).then((r) => r || caches.match('/index.html')))
44    );
45    return;
46  }
47
48  event.respondWith(
49    caches.match(request).then((cached) =>
50      cached || fetch(request).then((response) => {
51        if (response.status === 200) {
52          const copy = response.clone();
53          caches.open(CACHE_NAME).then((cache) => cache.put(request, copy));
54        }
55        return response;
56      }).catch(() => cached)
57    )
58  );
59});

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.