Skip to content

Commit 0053bdd

Browse files
feat: public/sw.js (#16)
1 parent 418f1f7 commit 0053bdd

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

public/sw.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const CACHE_NAME = "todo-app-v2";
2+
const ASSETS = ["/", "/index.html"];
3+
4+
self.addEventListener("install", (e) => {
5+
e.waitUntil(caches.open(CACHE_NAME).then(c => c.addAll(ASSETS)));
6+
self.skipWaiting();
7+
});
8+
9+
self.addEventListener("activate", (e) => {
10+
e.waitUntil(caches.keys().then(keys =>
11+
Promise.all(keys.filter(k => k !== CACHE_NAME).map(k => caches.delete(k)))
12+
));
13+
});
14+
15+
self.addEventListener("fetch", (e) => {
16+
e.respondWith(
17+
caches.match(e.request).then(cached => cached || fetch(e.request))
18+
);
19+
});

0 commit comments

Comments
 (0)