feat: delete old app assets caches; don't use date as version
This commit is contained in:
parent
91791b37b5
commit
4751ce9b80
2 changed files with 15 additions and 2 deletions
|
@ -6,4 +6,5 @@ export const SITE_AUTHOR_MASTODON = 'https://social.ayco.io/@ayo';
|
||||||
export const SITE_PROJECT_REPO = 'https://github.com/ayoayco/Cozy';
|
export const SITE_PROJECT_REPO = 'https://github.com/ayoayco/Cozy';
|
||||||
export const SITE_DESCRIPTION = 'The Web is Yours.';
|
export const SITE_DESCRIPTION = 'The Web is Yours.';
|
||||||
|
|
||||||
export const VERSION = 'Quivering-Quacks';
|
export const VERSION = 'Raging-Rabits';
|
||||||
|
// export const VERSION = 'Raging-Rabits-test-old';
|
14
src/sw.mjs
14
src/sw.mjs
|
@ -4,9 +4,20 @@ import { logInfo } from './utils/logger'
|
||||||
* -- find usage in `astro.config.mjs` integrations
|
* -- find usage in `astro.config.mjs` integrations
|
||||||
* @see https://ayco.io/n/@ayco/astro-sw
|
* @see https://ayco.io/n/@ayco/astro-sw
|
||||||
*/
|
*/
|
||||||
const cacheName = `${__prefix ?? 'app'}-v${__version + '-' + Date.now()}`
|
const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}`
|
||||||
const forceLogging = true;
|
const forceLogging = true;
|
||||||
|
|
||||||
|
const cleanOldCaches = async () => {
|
||||||
|
const allowCacheNames = ['cozy-reader', cacheName];
|
||||||
|
const allCaches = await caches.keys();
|
||||||
|
allCaches.forEach(key => {
|
||||||
|
if (!allowCacheNames.includes(key)) {
|
||||||
|
logInfo('Deleting old cache', {force: !!forceLogging, data: key});
|
||||||
|
caches.delete(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const addResourcesToCache = async (resources) => {
|
const addResourcesToCache = async (resources) => {
|
||||||
const cache = await caches.open(cacheName);
|
const cache = await caches.open(cacheName);
|
||||||
logInfo('adding resources to cache...', { force: !!forceLogging, context: 'cozy-sw', data: resources })
|
logInfo('adding resources to cache...', { force: !!forceLogging, context: 'cozy-sw', data: resources })
|
||||||
|
@ -107,6 +118,7 @@ const enableNavigationPreload = async () => {
|
||||||
|
|
||||||
self.addEventListener('activate', (event) => {
|
self.addEventListener('activate', (event) => {
|
||||||
logInfo('activating service worker...', { force: forceLogging, context: 'cozy-sw' })
|
logInfo('activating service worker...', { force: forceLogging, context: 'cozy-sw' })
|
||||||
|
cleanOldCaches();
|
||||||
event.waitUntil(enableNavigationPreload());
|
event.waitUntil(enableNavigationPreload());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue