fix: enable SW on localhost and optimize pre-cache sequence for faster feedback

This commit is contained in:
2025-12-21 00:18:38 +01:00
parent 716afce2ae
commit f0cb661d91
3 changed files with 13 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
const CACHE_NAME = 'whisky-vault-v10-bunker'; // Professional Bunker v10
const CACHE_NAME = 'whisky-vault-v11-offline'; // Professional Offline-Modus v11
// CONFIG: Core Pages & Static Assets
const CORE_PAGES = [
@@ -23,13 +23,13 @@ async function broadcast(message) {
}
// Helper: Fetch with Timeout & AbortController
async function fetchWithTimeout(url, timeoutMs = 15000) {
async function fetchWithTimeout(url, timeoutMs = 25000) {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeoutMs);
try {
const response = await fetch(url, {
signal: controller.signal,
cache: 'no-store' // Ensure we get fresh bits for the bunker
cache: 'no-store' // Ensure we get fresh bits
});
clearTimeout(id);
return response;
@@ -39,15 +39,16 @@ async function fetchWithTimeout(url, timeoutMs = 15000) {
}
}
// 🏗️ INSTALL: Build the Bunker
// 🏗️ INSTALL: Build the Offline-Modus
self.addEventListener('install', (event) => {
// Immediate takeover
self.skipWaiting();
event.waitUntil(
caches.open(CACHE_NAME).then(async (cache) => {
console.log('🏗️ PWA: Building Bunker v10...');
const items = [...CORE_PAGES, ...STATIC_ASSETS];
console.log('🏗️ PWA: Building Offline-Modus v11...');
// Load small static assets first for instant progress bar feedback
const items = [...STATIC_ASSETS, ...CORE_PAGES];
const total = items.length;
let loaded = 0;
@@ -94,9 +95,9 @@ self.addEventListener('activate', (event) => {
// 💬 MESSAGE: Handle status checks
self.addEventListener('message', (event) => {
if (event.data?.type === 'CHECK_BUNKER_STATUS') {
if (event.data?.type === 'CHECK_OFFLINE_STATUS') {
event.source.postMessage({
type: 'BUNKER_STATUS',
type: 'OFFLINE_STATUS',
isReady: true,
version: CACHE_NAME
});