Test für Base-Paths

This commit is contained in:
Dennis Heinrich 2025-04-06 01:18:00 +02:00
parent 474682252f
commit 87d0169a65

View file

@ -1,25 +1,27 @@
const CACHE_NAME = 'durst-rechner-v2';
const BASE_PATH = self.location.pathname.includes('DurstRechner') ? '/DurstRechner' : ''; // Handle GitHub Pages vs. Localhost
const FILES_TO_CACHE = [
'/',
'/index.html',
'/assets/manifest.json',
'/assets/script/service-worker.js',
'/assets/style/stylesheet.css',
'/assets/script/all.js',
'/assets/script/calculator.js',
'/assets/script/theme.js',
'/node_modules/bootstrap/dist/css/bootstrap.min.css',
'/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js',
'/node_modules/bootstrap-icons/font/bootstrap-icons.min.css',
'/node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff2',
'/node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff',
'/assets/favicon/android-chrome-192x192.png',
'/assets/favicon/android-chrome-512x512.png',
'/assets/favicon/apple-touch-icon.png',
'/assets/favicon/favicon-16x16.png',
'/assets/favicon/favicon-32x32.png',
'/assets/favicon/favicon.ico',
`${BASE_PATH}/index.html`,
`${BASE_PATH}/assets/manifest.json`,
`${BASE_PATH}/assets/script/service-worker.js`,
`${BASE_PATH}/assets/style/stylesheet.css`,
`${BASE_PATH}/assets/script/all.js`,
`${BASE_PATH}/assets/script/calculator.js`,
`${BASE_PATH}/assets/script/theme.js`,
`${BASE_PATH}/node_modules/bootstrap/dist/css/bootstrap.min.css`,
`${BASE_PATH}/node_modules/bootstrap/dist/js/bootstrap.bundle.min.js`,
`${BASE_PATH}/node_modules/bootstrap-icons/font/bootstrap-icons.min.css`,
`${BASE_PATH}/node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff2`,
`${BASE_PATH}/node_modules/bootstrap-icons/font/fonts/bootstrap-icons.woff`,
`${BASE_PATH}/assets/favicon/android-chrome-192x192.png`,
`${BASE_PATH}/assets/favicon/android-chrome-512x512.png`,
`${BASE_PATH}/assets/favicon/apple-touch-icon.png`,
`${BASE_PATH}/assets/favicon/favicon-16x16.png`,
`${BASE_PATH}/assets/favicon/favicon-32x32.png`,
`${BASE_PATH}/assets/favicon/favicon.ico`,
];
self.addEventListener('install', event => {
@ -33,10 +35,7 @@ self.addEventListener('install', event => {
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request).then(response => {
return response || fetch(event.request).catch(error => {
console.error('Fetch failed; returning offline page instead.', error);
return caches.match('/offline.html'); // If you have an offline page
});
return response || fetch(event.request);
})
);
});