init
This commit is contained in:
28
test.txt
Normal file
28
test.txt
Normal file
@@ -0,0 +1,28 @@
|
||||
self.addEventListener("install", function (event) {
|
||||
console.log("[SW install]", event);
|
||||
self.skipWaiting();
|
||||
event.waitUntil(
|
||||
caches.open("static").then((cache) => {
|
||||
console.log("[SW precache]");
|
||||
return cache.addAll(["/", "/index.html", "/js/app.js"]);
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("activate", function (event) {
|
||||
console.log("[SW activate]", event);
|
||||
return self.clients.claim();
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", function (event) {
|
||||
event.respondWith(
|
||||
caches.match(event.request).then((res) => {
|
||||
console.log("res", res);
|
||||
if (res) {
|
||||
return res;
|
||||
} else {
|
||||
return fetch(event.request);
|
||||
}
|
||||
}),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user