File size: 1,004 Bytes
e9b92bb
bc241ad
2b342f6
 
 
 
bc241ad
e9b92bb
bc241ad
2b342f6
 
 
 
 
 
 
 
 
 
a59a059
 
bc241ad
2b342f6
 
 
 
 
 
 
 
 
 
 
 
 
a59a059
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
const CACHE_NAME = 'pawmatch-v1';
const urlsToCache = [
    './',
    './manifest.json',
    './assets/icon-192.png',
    './assets/icon-512.png'
];

self.addEventListener('install', function(event) {
    event.waitUntil(
        caches.open(CACHE_NAME)
            .then(function(cache) {
                console.log('Cache opened successfully');
                return cache.addAll(urlsToCache);
            })
            .catch(function(error) {
                console.error('Cache initialization failed:', error);
            })
    );
});

self.addEventListener('fetch', function(event) {
    event.respondWith(
        caches.match(event.request)
            .then(function(response) {
                if (response) {
                    return response;
                }
                return fetch(event.request);
            })
            .catch(function(error) {
                console.error('Fetch failed:', error);
                return fetch(event.request);
            })
    );
});