2024-09-10 15:58:20 +02:00
|
|
|
|
const cacheVersion = "0.271"
|
2024-08-22 10:13:16 +02:00
|
|
|
|
const cacheName = "speedtech-brainminder"
|
|
|
|
|
const cacheFiles = [
|
|
|
|
|
'/static/bootstrap-icons/font/bootstrap-icons.min.css',
|
|
|
|
|
'/static/bootstrap-icons/font/fonts/bootstrap-icons.woff',
|
|
|
|
|
'/static/bootstrap-icons/font/fonts/bootstrap-icons.woff2',
|
|
|
|
|
'/static/bootstrap-icons/*.svg',
|
|
|
|
|
"/static/easymde/easymde.min.css",
|
2024-09-10 15:58:20 +02:00
|
|
|
|
'/static/css/slimselect.css',
|
2024-08-22 10:13:16 +02:00
|
|
|
|
'/static/css/main.css',
|
|
|
|
|
'/static/img/brainminder.svg',
|
|
|
|
|
'/static/img/brainminder-icon.svg',
|
|
|
|
|
"/static/easymde/easymde.min.js",
|
|
|
|
|
"/static/js/Sortable.min.js",
|
|
|
|
|
"/static/js/htmx/htmx.min.js",
|
|
|
|
|
"/static/js/hyperscript.min.js",
|
|
|
|
|
"/static/js/handlebars.js",
|
|
|
|
|
"/static/js/templates.js",
|
2024-09-10 15:58:20 +02:00
|
|
|
|
"/static/js/slimselect.min.js",
|
2024-08-22 10:13:16 +02:00
|
|
|
|
'/static/js/main.js',
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
self.addEventListener('install', function(e) {
|
|
|
|
|
e.waitUntil(
|
|
|
|
|
// Open the cache
|
|
|
|
|
caches.open(cacheName).then(function(cache) {
|
|
|
|
|
// Add all the default files to the cache
|
|
|
|
|
console.log('[ServiceWorker] Caching cacheFiles');
|
|
|
|
|
return cache.addAll(cacheFiles);
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', function(e) {
|
|
|
|
|
e.waitUntil(
|
|
|
|
|
// Get all the cache keys (cacheName)
|
|
|
|
|
caches.keys().then(function(cacheNames) {
|
|
|
|
|
return Promise.all(cacheNames.map(function(thisCacheName) {
|
|
|
|
|
// If a cached item is saved under a previous cacheName
|
|
|
|
|
if (thisCacheName !== cacheName) {
|
|
|
|
|
// Delete that cached file
|
|
|
|
|
console.log('[ServiceWorker] Removing Cached Files from Cache - ', thisCacheName);
|
|
|
|
|
return caches.delete(thisCacheName);
|
|
|
|
|
}
|
|
|
|
|
}));
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('fetch', (event) => {
|
|
|
|
|
// Respond to the document with what is returned from
|
|
|
|
|
event.respondWith(
|
|
|
|
|
// 1. Check the cache if a file matching that request is available
|
|
|
|
|
caches.match(event.request).then((response) => {
|
|
|
|
|
// 2. If it is, respond to the document with the file from the cache
|
|
|
|
|
if (response) return response
|
|
|
|
|
// 3. If it isn’t, fetch the file from the network and respond to the document with the fetched file
|
|
|
|
|
return fetch(event.request)
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
});
|