Better caching
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "card-forge",
|
"name": "card-forge",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.1",
|
"version": "0.0.2",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite dev",
|
"dev": "vite dev",
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
birthday: mapping.birthday !== -1 ? row[mapping.birthday] || '' : '',
|
birthday: mapping.birthday !== -1 ? row[mapping.birthday] || '' : '',
|
||||||
pictureUrl,
|
pictureUrl,
|
||||||
alreadyPrinted,
|
alreadyPrinted,
|
||||||
_rowIndex: index + 2,
|
_rowIndex: index + 1,
|
||||||
_valid: isValid,
|
_valid: isValid,
|
||||||
_checked: false
|
_checked: false
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ self.addEventListener('install', (event) => {
|
|||||||
await cache.addAll(ASSETS);
|
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) => {
|
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) => {
|
self.addEventListener('fetch', (event) => {
|
||||||
@@ -64,7 +69,9 @@ self.addEventListener('fetch', (event) => {
|
|||||||
throw new Error('invalid response from fetch');
|
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());
|
cache.put(event.request, response.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user