tangled
alpha
login
or
join now
leaflet.pub
/
leaflet
289
fork
atom
a tool for shared writing and social publishing
289
fork
atom
overview
issues
27
pulls
pipelines
remove logs and add install + skipwaiting to worker
awarm.space
2 years ago
778a2f48
3680afdf
+10
-5
2 changed files
expand all
collapse all
unified
split
components
ServiceWorker.tsx
public
worker.js
+1
-1
components/ServiceWorker.tsx
···
4
4
export function ServiceWorker() {
5
5
useEffect(() => {
6
6
if ("serviceWorker" in navigator) {
7
7
-
navigator.serviceWorker.register("/worker.js").then(console.log);
7
7
+
navigator.serviceWorker.register("/worker.js");
8
8
}
9
9
}, []);
10
10
return null;
+9
-4
public/worker.js
···
1
1
self.addEventListener("fetch", (event) => {
2
2
-
console.log("Handling fetch event for", event.request.url);
3
3
-
4
2
event.respondWith(
5
3
caches.open("minilink-user-assets").then(async (cache) => {
6
4
return cache
7
5
.match(event.request)
8
6
.then((response) => {
9
7
if (response) {
10
10
-
console.log("cache match");
11
8
return response;
12
9
}
13
13
-
console.log("cache miss");
14
10
return fetch(event.request.clone());
15
11
})
16
12
.catch((error) => {
···
20
16
}),
21
17
);
22
18
});
19
19
+
20
20
+
self.addEventListener("install", () => {
21
21
+
// The promise that skipWaiting() returns can be safely ignored.
22
22
+
self.skipWaiting();
23
23
+
24
24
+
// Perform any other actions required for your
25
25
+
// service worker to install, potentially inside
26
26
+
// of event.waitUntil();
27
27
+
});