aboutsummaryrefslogtreecommitdiff
path: root/webAO/sw.js
diff options
context:
space:
mode:
authorcaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-07 00:33:14 -0500
committercaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-07 00:33:14 -0500
commit7beba90d2ef87005fe6e12a4786101ea97c5e4fd (patch)
tree0f39ee8bacdc6f7933db04789b309631052b9778 /webAO/sw.js
parentccbca8b9cede972480dd1ef7a73db71a99be9609 (diff)
Now a PWA
Diffstat (limited to 'webAO/sw.js')
-rw-r--r--webAO/sw.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/webAO/sw.js b/webAO/sw.js
new file mode 100644
index 0000000..aba104a
--- /dev/null
+++ b/webAO/sw.js
@@ -0,0 +1,29 @@
+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
+ return 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 => {
+ return response || fetch(event.request);
+ })
+ );
+});