a bit of cleanup, better naming of the app cache

This commit is contained in:
or-else
2021-05-08 18:01:14 -07:00
parent 62259ab331
commit aa8d60cc1d
14 changed files with 428 additions and 418 deletions
+4 -4
View File
@@ -2,6 +2,7 @@
importScripts('https://cdn.jsdelivr.net/npm/firebase@8.2.9/firebase-app.js');
importScripts('https://cdn.jsdelivr.net/npm/firebase@8.2.9/firebase-messaging.js');
importScripts('firebase-init.js');
importScripts('version.js');
// Channel to notify the webapp.
const webAppChannel = new BroadcastChannel('tinode-sw');
@@ -132,18 +133,17 @@ self.addEventListener('fetch', event => {
return response;
}
if (event.request.url && (event.request.url.startsWith('http://') || event.request.url.startsWith('https://'))) {
const cache = await caches.open(self.version);
const cache = await caches.open(PACKAGE_VERSION);
await cache.put(event.request, response.clone());
}
return response;
})());
});
// This code get the human language & app version from the webapp.
// Locale is used for localization of strings, version for naming the cache.
// This code get the human language from the webapp.
// Locale is used for localization of strings.
self.addEventListener('message', event => {
const data = JSON.parse(event.data);
self.locale = data.locale || '';
self.baseLocale = self.locale.toLowerCase().split(/[-_]/)[0];
self.version = data.version || 'default';
});