-
Notifications
You must be signed in to change notification settings - Fork 0
/
swGenerator.js
31 lines (30 loc) · 1.07 KB
/
swGenerator.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
const sw = "sw.js"; // it is needed because parcel will not recognize this as a file and not precess in its manner
if ("serviceWorker" in navigator) {
window.addEventListener("load", function () {
navigator.serviceWorker
.register(sw)
.then((registration) => {
registration.onupdatefound = () => {
const installingWorker = registration.installing;
if (installingWorker == null) {
return;
}
installingWorker.onstatechange = () => {
if (installingWorker.state === "installed") {
if (navigator.serviceWorker.controller) {
console.log(
"New content is available and will be used when all " +
"tabs for this page are closed. See https://bit.ly/CRA-PWA."
);
} else {
console.log("Content is cached for offline use.");
}
}
};
};
})
.catch((error) => {
console.error("Error during service worker registration:", error);
});
});
}