generated from nhcarrigan/template
feat: Multiple Features, Accessibility, Security, and UX Improvements #59
@@ -11,11 +11,6 @@ const IMAGE_CACHE = `${CACHE_VERSION}-images`;
|
|||||||
|
|
||||||
// Static assets to cache on install
|
// Static assets to cache on install
|
||||||
const STATIC_ASSETS = [
|
const STATIC_ASSETS = [
|
||||||
'/',
|
|
||||||
'/index.html',
|
|
||||||
'/main.js',
|
|
||||||
'/runtime.js',
|
|
||||||
'/styles.css',
|
|
||||||
'/offline.html'
|
'/offline.html'
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -27,6 +22,8 @@ self.addEventListener('install', (event) => {
|
|||||||
console.log('[Service Worker] Caching static assets');
|
console.log('[Service Worker] Caching static assets');
|
||||||
return cache.addAll(STATIC_ASSETS).catch((err) => {
|
return cache.addAll(STATIC_ASSETS).catch((err) => {
|
||||||
console.error('[Service Worker] Failed to cache static assets:', err);
|
console.error('[Service Worker] Failed to cache static assets:', err);
|
||||||
|
// Don't fail installation if caching fails
|
||||||
|
return Promise.resolve();
|
||||||
});
|
});
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
return self.skipWaiting();
|
return self.skipWaiting();
|
||||||
@@ -137,10 +134,13 @@ self.addEventListener('fetch', (event) => {
|
|||||||
event.respondWith(
|
event.respondWith(
|
||||||
fetch(request)
|
fetch(request)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
const responseClone = response.clone();
|
// Only cache successful responses
|
||||||
caches.open(DYNAMIC_CACHE).then((cache) => {
|
if (response.ok) {
|
||||||
cache.put(request, responseClone);
|
const responseClone = response.clone();
|
||||||
});
|
caches.open(DYNAMIC_CACHE).then((cache) => {
|
||||||
|
cache.put(request, responseClone);
|
||||||
|
});
|
||||||
|
}
|
||||||
return response;
|
return response;
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user