-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsw.js
More file actions
89 lines (84 loc) · 2.81 KB
/
sw.js
File metadata and controls
89 lines (84 loc) · 2.81 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const CACHE_NAME = 'securing.guide-v1.1';
self.addEventListener('install', (event) => {
self.skipWaiting(); // Make this SW activate immediately
event.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll([
'/',
'/2fa',
'/discord',
'/minecraft',
'/tiktok',
'/twitch',
'/epic',
'/snapchat',
'/kick',
'/twitter',
'/valorant',
'/instagram',
'/playstation',
'/steam',
'/steam-id',
'/js/generate.js',
'/js/steamid.js',
'/guides/discord.js',
'/guides/minecraft.js',
'/guides/steam.js',
'/guides/tiktok.js',
'/guides/twitch.js',
'/guides/epic.js',
'/guides/snapchat.js',
'/guides/kick.js',
'/guides/twitter.js',
'/guides/valorant.js',
'/guides/instagram.js',
'/guides/playstation.js',
'https://cdnjs.cloudflare.com/ajax/libs/popper.js/2.11.8/umd/popper.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/tippy.js/6.3.7/tippy.umd.min.js',
'https://totp.codes/js/rolling-number.js'
]))
);
});
self.addEventListener('activate', (event) => {
self.clients.claim(); // Take control of clients immediately
event.waitUntil(
caches.keys().then((keys) =>
Promise.all(
keys.map((key) => {
if (key !== CACHE_NAME) {
return caches.delete(key);
}
})
)
)
);
});
self.addEventListener('fetch', (event) => {
// Always try the network first
event.respondWith(
fetch(event.request)
.then((networkResponse) => {
const cloned = networkResponse.clone();
// If it's a good response, cache it
if (
networkResponse &&
(networkResponse.type === 'basic' || networkResponse.type === 'cors') &&
networkResponse.status === 200
) {
caches.open(CACHE_NAME).then((cache) => {
cache.put(event.request, cloned);
});
}
return networkResponse;
})
.catch(() => {
// If network fails, use cache
return caches.match(event.request).then((cachedResponse) => {
// For navigation fallback
if (!cachedResponse && event.request.mode === 'navigate') {
return caches.match('/');
}
return cachedResponse;
});
})
);
});