aboutsummaryrefslogtreecommitdiff
path: root/webAO/sw.js
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-03-09 07:36:18 +0100
committerGitHub <noreply@github.com>2022-03-09 07:36:18 +0100
commit679bc9be8b0459d298ac1ac3f3b7e61278c184d9 (patch)
tree7025ffb3527bf78fd100a1f1bb9bf6aaa7752470 /webAO/sw.js
parent91c3769a78e59924a73db6c759844a9026e8da00 (diff)
parent68169fb20e0406a3bf90ff6a56acb7c1b5a7ed5f (diff)
Merge pull request #98 from caleb-mabry/become-a-pwa
Turn Application into a PWA
Diffstat (limited to 'webAO/sw.js')
-rw-r--r--webAO/sw.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/webAO/sw.js b/webAO/sw.js
new file mode 100644
index 0000000..09a2251
--- /dev/null
+++ b/webAO/sw.js
@@ -0,0 +1,26 @@
+const cacheName = 'webAO';
+
+// Cache all the files to make a PWA
+self.addEventListener('install', (e) => {
+ e.waitUntil(
+ caches.open(cacheName).then((cache) =>
+ // Our application only has two files here index.html and manifest.json
+ // but you can add more such as style.css as your app grows
+ cache.addAll([
+ './',
+ './index.html',
+ '../manifest.json',
+ ])),
+ );
+});
+
+// Our service worker will intercept all fetch requests
+// and check if we have cached the file
+// if so it will serve the cached file
+self.addEventListener('fetch', (event) => {
+ event.respondWith(
+ caches.open(cacheName)
+ .then((cache) => cache.match(event.request, { ignoreSearch: true }))
+ .then((response) => response || fetch(event.request)),
+ );
+});