diff --git a/.gitignore b/.gitignore index 23b4e83..8e48028 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ dist/ .output/ .astro/ +.continue/ # dependencies node_modules/ diff --git a/src/sw.mjs b/src/sw.mjs index e8b8695..314ab1f 100644 --- a/src/sw.mjs +++ b/src/sw.mjs @@ -6,13 +6,28 @@ const cacheName = `${__prefix ?? 'app'}-v${__version ?? '000'}` const forceLogging = true +/** + * Cleans up old service worker caches by deleting any cache that doesn't match the current cache name. + * This ensures only the current version of the application's cache is retained. + * @async + * @function cleanOldCaches + * @returns {Promise} A promise that resolves when old caches have been deleted + */ const cleanOldCaches = async () => { const allowCacheNames = [cacheName] const allCaches = await caches.keys() allCaches.forEach((key) => { if (!allowCacheNames.includes(key)) { console.info('Deleting old cache', key) - caches.delete(key) + caches + .delete(key) + + .then(() => { + console.info('Successfully deleted cache:', key) + }) + .catch((error) => { + console.warn('Failed to delete old cache:', key, error) + }) } }) }