-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.js
More file actions
53 lines (52 loc) · 1.67 KB
/
site.js
File metadata and controls
53 lines (52 loc) · 1.67 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
// Cache important resources during installation
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('my-cache').then((cache) => {
return cache.addAll([
'/index.html',
'geometry.jpeg',
'square.png',
'cubeMarkup.jpeg',
'trigonometry.png',
'pentagon.png',
'areaOfACircle.jpg',
'circleSegment.jpg',
'circumference.jpg',
'sphereAndCubeMarkup.jpeg',
'sphericalCap.jpg',
'coneAndSphereMarkup.jpeg',
'sphereAndCone.jpeg',
'octantSphereQuarterCone.jpeg',
'coneAndSphereComparison.png',
'coneMarkup.jpeg',
'frustumOfConeMarkup.png',
'conePyramidVolumeMarkup.jpeg',
'frustumOfPyramidMarkup.png',
'tetraFrame.jpeg',
'tetrahedronMarkup.jpeg'
]);
})
);
});
// Serve cached content or fetch from network
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => {
// Check if the request is for an image
if (event.request.destination === 'image') {
return response || fetch(event.request).then((networkResponse) => {
// Cache the new image and return the network response
return caches.open('my-cache').then((cache) => {
cache.put(event.request, networkResponse.clone());
return networkResponse;
});
});
}
// For other requests, return the cached response or fetch from network
return response || fetch(event.request).catch(() => {
// Return the cached page if fetch fails
return caches.match('/index.html');
});
})
);
});