-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
68 lines (63 loc) · 1.59 KB
/
service-worker.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// File: service-worker.js
// Set the name of the cache storage
const CACHE_NAME = 'my-cache-v1';
// Define the list of files to cache
const FILES_TO_CACHE = [
'/',
'/index.html',
'/style.css',
'/quari/salem.html',
'/quari/souleyman.html',
'/quari/naji.html',
'/quari/rajil.html',
'/quari/chaikna.html',
'/quari/hassen.html',
'/quari/style1.css',
'/quari/JS/salem.js',
'/quari/JS/souleyman.js',
'/quari/JS/naji.js',
'/quari/JS/rajil.js',
'/quari/JS/chaikna.js',
'/quari/JS/hassen.js',
'/img/icon.png',
'/fonts/DTHULUTH.ttf'
'/fonts/Suls.ttf'
];
// Add event listener for the 'install' event
self.addEventListener('install', (event) => {
// Perform the install steps
event.waitUntil(
caches.open(CACHE_NAME)
.then((cache) => {
console.log('Opened cache');
return cache.addAll(FILES_TO_CACHE);
})
);
});
// Add event listener for the 'fetch' event
self.addEventListener('fetch', (event) => {
// Check if the request is in the cache
event.respondWith(
caches.match(event.request)
.then((response) => {
// Return the cached response, or fetch from the network
return response || fetch(event.request);
})
);
});
// Add event listener for the 'activate' event
self.addEventListener('activate', (event) => {
// Remove old caches
const cacheWhitelist = [CACHE_NAME];
event.waitUntil(
caches.keys().then((cacheNames) => {
return Promise.all(
cacheNames.map((cacheName) => {
if (cacheWhitelist.indexOf(cacheName) === -1) {
return caches.delete(cacheName);
}
})
);
})
);
});