PageSourceSearch

https://loomia-ads.vercel.app/sw.js

js loomia-ads.vercel.app collected 2026-10-03 07:15:27 UTC 2,048 bytes, 72 lines download raw bytes

1const CACHE_NAME = 'loomia-v1';
2const STATIC_ASSETS = ['/', '/icon?size=192', '/icon?size=512'];
3
4// Install: cache static assets
5self.addEventListener('install', (event) => {
6  event.waitUntil(
7    caches.open(CACHE_NAME).then((cache) => cache.addAll(STATIC_ASSETS))
8  );
9  self.skipWaiting();
10});
11
12// Activate: clean old caches
13self.addEventListener('activate', (event) => {
14  event.waitUntil(
15    caches.keys().then((keys) =>
16      Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
17    )
18  );
19  self.clients.claim();
20});
21
22// Fetch: network-first for API, cache-first for static
23self.addEventListener('fetch', (event) => {
24  const { request } = event;
25  const url = new URL(request.url);
26
27  // Skip non-GET and API requests
28  if (request.method !== 'GET' || url.pathname.startsWith('/api/')) {
29    return;
30  }
31
32  event.respondWith(
33    fetch(request)
34      .then((response) => {
35        const clone = response.clone();
36        caches.open(CACHE_NAME).then((cache) => cache.put(request, clone));
37        return response;
38      })
39      .catch(() => caches.match(request))
40  );
41});
42
43// Push notifications
44self.addEventListener('push', (event) => {
45  const data = event.data?.json() || {};
46  const title = data.title || 'Loomia Ads';
47  const options = {
48    body: data.body || 'Notificação do sistema',
49    icon: '/icon?size=192',
50    badge: '/icon?size=72',
51    tag: data.tag || 'loomia-notification',
52    data: { url: data.url || '/' },
53    actions: data.actions || [],
54    vibrate: [200, 100, 200],
55  };
56
57  event.waitUntil(self.registration.showNotification(title, options));
58});
59
60// Notification click: open/focus the app
61self.addEventListener('notificationclick', (event) => {
62  event.notification.close();
63  const url = event.notification.data?.url || '/';
64
65  event.waitUntil(
66    self.clients.matchAll({ type: 'window' }).then((clients) => {
67      const existing = clients.find((c) => c.url.includes(url));
68      if (existing) return existing.focus();
69      return self.clients.openWindow(url);
70    })
71  );
72});

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.