Fix caching mistake

This commit is contained in:
Kevin Kandlbinder 2022-05-03 16:41:18 +02:00
parent ca0a6cf102
commit 8bd7891ef8
2 changed files with 20 additions and 2 deletions

View file

@ -1,6 +1,6 @@
{ {
"name": "kevins-data-toolbox", "name": "kevins-data-toolbox",
"version": "2.2.3", "version": "2.2.4",
"private": true, "private": true,
"dependencies": { "dependencies": {
"@loadable/component": "^5.15.0", "@loadable/component": "^5.15.0",

View file

@ -14,12 +14,13 @@ import { precacheAndRoute, createHandlerBoundToURL } from 'workbox-precaching';
import { registerRoute } from 'workbox-routing'; import { registerRoute } from 'workbox-routing';
import { StaleWhileRevalidate } from 'workbox-strategies'; import { StaleWhileRevalidate } from 'workbox-strategies';
import {setCacheNameDetails} from 'workbox-core'; import {setCacheNameDetails} from 'workbox-core';
import {version} from '../package.json';
declare const self: ServiceWorkerGlobalScope; declare const self: ServiceWorkerGlobalScope;
setCacheNameDetails({ setCacheNameDetails({
prefix: 'kevins-toolbox', prefix: 'kevins-toolbox',
suffix: 'v1', suffix: 'v'+version,
precache: 'precache', precache: 'precache',
runtime: 'runtime' runtime: 'runtime'
}); });
@ -96,3 +97,20 @@ registerRoute(
plugins: [] plugins: []
}) })
) )
self.addEventListener('activate', function(event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
if (cacheName.startsWith('kevins-toolbox') && cacheName !== 'kevins-toolbox-precache-v'+version) {
return true;
}
return false;
}).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});