-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsite.js
More file actions
56 lines (55 loc) · 1.69 KB
/
site.js
File metadata and controls
56 lines (55 loc) · 1.69 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
// Cache important resources during installation
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('my-cache').then((cache) => {
return cache.addAll([
'/index.html',
'circle.png',
'circumference.png',
'sphere.jpeg',
'coneAndSphere.jpeg',
'octantSphereQuarterCone.jpeg',
'sphereAndCone.jpeg',
'trigonometry.png',
'sphereSurface.jpeg',
'polygon.png',
'circleSegment.png',
'cone.jpeg',
'conePyramidVolume.jpeg',
'tetraFrame.jpeg',
'frustumPyramid.jpeg',
'frustumCone.jpeg',
'tetrahedron.jpeg',
'isoperimetry.png',
'polygonApproximation.png',
'equityFigure.png',
'circleArea.png',
'cubeDissection.jpeg',
'square.png',
'cube.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');
});
})
);
});