From 87d0169a65597d54f039ea217d1b3679569a9d77 Mon Sep 17 00:00:00 2001 From: Dennis Heinrich Date: Sun, 6 Apr 2025 01:18:00 +0200 Subject: [PATCH] =?UTF-8?q?Test=20f=C3=BCr=20Base-Paths?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/script/service-worker.js | 43 ++++++++++++++++----------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/assets/script/service-worker.js b/assets/script/service-worker.js index 1d37464..2d0c044 100644 --- a/assets/script/service-worker.js +++ b/assets/script/service-worker.js @@ -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); }) ); });