Progressive Web App

This commit is contained in:
Simon Gardling
2022-04-20 14:23:48 -04:00
parent 9afa4d86bc
commit 1082aa31b4
11 changed files with 178 additions and 105 deletions

25
www/sw.js Normal file
View File

@@ -0,0 +1,25 @@
var cacheName = 'ytbn-graphing-software-pwa';
var filesToCache = [
'./',
'./index.html',
'./ytbn_graphing_software.js',
'./ytbn_graphing_software_bg.wasm',
];
/* Start the service worker and cache all of the app's content */
self.addEventListener('install', function (e) {
e.waitUntil(
caches.open(cacheName).then(function (cache) {
return cache.addAll(filesToCache);
})
);
});
/* Serve cached content when offline */
self.addEventListener('fetch', function (e) {
e.respondWith(
caches.match(e.request).then(function (response) {
return response || fetch(e.request);
})
);
});