diff --git a/public/sw.js b/public/sw.js index 7d2092c..17e5f6a 100644 --- a/public/sw.js +++ b/public/sw.js @@ -1,6 +1,6 @@ /* İhaleist service worker — uygulama kabuğu çevrimdışı açılır, API her zaman ağdan. Sürüm değişince eski önbellek temizlenir (build her deploy'da yeni asset adı üretir). */ -const SURUM = 'ihaleist-v1'; +const SURUM = 'ihaleist-v2'; // v2: yanlış MIME ile saklanmış pdf worker kopyaları temizlensin const KABUK = ['/', '/manifest.webmanifest', '/icons/icon-192.png', '/icons/icon-512.png']; self.addEventListener('install', (e) => { @@ -17,7 +17,15 @@ self.addEventListener('fetch', (e) => { // Hash'li build varlıkları: cache-first (değişmez adlar) if (url.pathname.startsWith('/assets/')) { e.respondWith(caches.match(e.request).then((hit) => hit || fetch(e.request).then((r) => { - const kopya = r.clone(); caches.open(SURUM).then((c) => c.put(e.request, kopya)); return r; + // Yalnızca sağlıklı yanıt saklanır: 404 veya JavaScript dosyasının + // yanlış MIME tipiyle (octet-stream) gelmesi önbelleğe girerse + // sunucu düzeltilse bile kullanıcı eski bozuk kopyayı görmeye devam eder. + const tip = r.headers.get('content-type') || ''; + const jsMi = /\.m?js$/.test(url.pathname); + if (r.ok && (!jsMi || /javascript|ecmascript/i.test(tip))) { + const kopya = r.clone(); caches.open(SURUM).then((c) => c.put(e.request, kopya)); + } + return r; }))); return; }