Better caching
All checks were successful
Build Docker image / build (push) Successful in 2m20s
Build Docker image / deploy (push) Successful in 3s
Build Docker image / verify (push) Successful in 36s

This commit is contained in:
Roman Krček
2025-08-11 16:47:08 +02:00
parent be7bdc551a
commit 82395afa6e
3 changed files with 12 additions and 5 deletions

View File

@@ -1,7 +1,7 @@
{
"name": "card-forge",
"private": true,
"version": "0.0.1",
"version": "0.0.2",
"type": "module",
"scripts": {
"dev": "vite dev",

View File

@@ -72,7 +72,7 @@
birthday: mapping.birthday !== -1 ? row[mapping.birthday] || '' : '',
pictureUrl,
alreadyPrinted,
_rowIndex: index + 2,
_rowIndex: index + 1,
_valid: isValid,
_checked: false
};

View File

@@ -16,7 +16,8 @@ self.addEventListener('install', (event) => {
await cache.addAll(ASSETS);
}
event.waitUntil(addFilesToCache());
// Precache and activate this SW immediately so new versions take control
event.waitUntil(Promise.all([addFilesToCache(), self.skipWaiting()]))
});
self.addEventListener('activate', (event) => {
@@ -27,7 +28,11 @@ self.addEventListener('activate', (event) => {
}
}
event.waitUntil(deleteOldCaches());
// Clean old caches and take control of existing clients immediately
event.waitUntil((async () => {
await deleteOldCaches();
await self.clients.claim();
})());
});
self.addEventListener('fetch', (event) => {
@@ -64,7 +69,9 @@ self.addEventListener('fetch', (event) => {
throw new Error('invalid response from fetch');
}
if (response.status === 200) {
// Only cache successful same-origin GET responses at runtime
if (response.status === 200 && url.origin === self.location.origin) {
cache.put(event.request, response.clone());
}