PageSourceSearch

https://historiadeafrica.com/sw.js

js historiadeafrica.com collected 2026-10-02 13:52:46 UTC 2,884 bytes, 115 lines download raw bytes

1const CACHE_NAME = 'historia-africa-v1';
2const OFFLINE_URL = '/offline.html';
3
4const STATIC_ASSETS = [
5  '/',
6  '/offline.html',
7  '/manifest.json',
8];
9
10const API_CACHE = 'historia-africa-api-v1';
11
12self.addEventListener('install', (event) => {
13  event.waitUntil(
14    caches.open(CACHE_NAME).then((cache) => {
15      return cache.addAll(STATIC_ASSETS);
16    })
17  );
18  self.skipWaiting();
19});
20
21self.addEventListener('activate', (event) => {
22  event.waitUntil(
23    caches.keys().then((cacheNames) => {
24      return Promise.all(
25        cacheNames
26          .filter((cacheName) => {
27            return cacheName !== CACHE_NAME && cacheName !== API_CACHE;
28          })
29          .map((cacheName) => caches.delete(cacheName))
30      );
31    })
32  );
33  self.clients.claim();
34});
35
36self.addEventListener('fetch', (event) => {
37  const { request } = event;
38  const url = new URL(request.url);
39
40  if (request.method !== 'GET') {
41    return;
42  }
43
44  if (url.origin === location.origin && url.pathname === '/') {
45    event.respondWith(
46      fetch(request)
47        .then((response) => {
48          const responseClone = response.clone();
49          caches.open(CACHE_NAME).then((cache) => {
50            cache.put(request, responseClone);
51          });
52          return response;
53        })
54        .catch(() => {
55          return caches.match(request).then((response) => {
56            return response || caches.match(OFFLINE_URL);
57          });
58        })
59    );
60    return;
61  }
62
63  if (url.hostname.includes('supabase')) {
64    event.respondWith(
65      fetch(request)
66        .then((response) => {
67          if (response.ok) {
68            const responseClone = response.clone();
69            caches.open(API_CACHE).then((cache) => {
70              cache.put(request, responseClone);
71            });
72          }
73          return response;
74        })
75        .catch(() => {
76          return caches.match(request);
77        })
78    );
79    return;
80  }
81
82  if (request.destination === 'image') {
83    event.respondWith(
84      caches.match(request).then((cachedResponse) => {
85        return (
86          cachedResponse ||
87          fetch(request).then((response) => {
88            if (response.ok) {
89              const responseClone = response.clone();
90              caches.open(CACHE_NAME).then((cache) => {
91                cache.put(request, responseClone);
92              });
93            }
94            return response;
95          })
96        );
97      })
98    );
99    return;
100  }
101
102  event.respondWith(
103    fetch(request).catch(() => {
104      return caches.match(request).then((response) => {
105        return response || caches.match(OFFLINE_URL);
106      });
107    })
108  );
109});
110
111self.addEventListener('message', (event) => {
112  if (event.data && event.data.type === 'SKIP_WAITING') {
113    self.skipWaiting();
114  }
115});

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.