Update service-worker.js
Browse files- service-worker.js +8 -8
service-worker.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
const CACHE_NAME = 'teplostil-cache-
|
| 2 |
const URLS_TO_CACHE = [
|
| 3 |
'/',
|
| 4 |
'/index.html',
|
|
@@ -16,7 +16,7 @@ self.addEventListener('install', (event) => {
|
|
| 16 |
return cache.addAll(URLS_TO_CACHE);
|
| 17 |
})
|
| 18 |
);
|
| 19 |
-
self.skipWaiting();
|
| 20 |
});
|
| 21 |
|
| 22 |
// Активация и удаление старых кэшей
|
|
@@ -33,25 +33,26 @@ self.addEventListener('activate', (event) => {
|
|
| 33 |
);
|
| 34 |
})
|
| 35 |
);
|
| 36 |
-
self.clients.claim();
|
| 37 |
});
|
| 38 |
|
| 39 |
// Обработка запросов
|
| 40 |
self.addEventListener('fetch', (event) => {
|
| 41 |
const requestUrl = new URL(event.request.url);
|
| 42 |
|
| 43 |
-
// Пропускаем запросы к внешнему iframe
|
| 44 |
if (requestUrl.origin !== self.location.origin) {
|
|
|
|
| 45 |
event.respondWith(
|
| 46 |
-
fetch(event.request).catch(() => {
|
| 47 |
-
|
| 48 |
return new Response('Network error occurred', { status: 503 });
|
| 49 |
})
|
| 50 |
);
|
| 51 |
return;
|
| 52 |
}
|
| 53 |
|
| 54 |
-
// Для навигационных запросов
|
| 55 |
if (event.request.mode === 'navigate') {
|
| 56 |
event.respondWith(
|
| 57 |
caches.match('/index.html').then((response) => {
|
|
@@ -63,7 +64,6 @@ self.addEventListener('fetch', (event) => {
|
|
| 63 |
event.respondWith(
|
| 64 |
caches.match(event.request).then((response) => {
|
| 65 |
return response || fetch(event.request).then((networkResponse) => {
|
| 66 |
-
// Кэшируем только локальные ресурсы
|
| 67 |
if (requestUrl.origin === self.location.origin) {
|
| 68 |
return caches.open(CACHE_NAME).then((cache) => {
|
| 69 |
cache.put(event.request, networkResponse.clone());
|
|
|
|
| 1 |
+
const CACHE_NAME = 'teplostil-cache-v5'; // Обновляем версию кэша
|
| 2 |
const URLS_TO_CACHE = [
|
| 3 |
'/',
|
| 4 |
'/index.html',
|
|
|
|
| 16 |
return cache.addAll(URLS_TO_CACHE);
|
| 17 |
})
|
| 18 |
);
|
| 19 |
+
self.skipWaiting();
|
| 20 |
});
|
| 21 |
|
| 22 |
// Активация и удаление старых кэшей
|
|
|
|
| 33 |
);
|
| 34 |
})
|
| 35 |
);
|
| 36 |
+
self.clients.claim();
|
| 37 |
});
|
| 38 |
|
| 39 |
// Обработка запросов
|
| 40 |
self.addEventListener('fetch', (event) => {
|
| 41 |
const requestUrl = new URL(event.request.url);
|
| 42 |
|
| 43 |
+
// Пропускаем запросы к внешнему iframe
|
| 44 |
if (requestUrl.origin !== self.location.origin) {
|
| 45 |
+
console.log('Пропускаем внешний запрос:', requestUrl.href);
|
| 46 |
event.respondWith(
|
| 47 |
+
fetch(event.request).catch((error) => {
|
| 48 |
+
console.error('Ошибка при внешнем запросе:', error);
|
| 49 |
return new Response('Network error occurred', { status: 503 });
|
| 50 |
})
|
| 51 |
);
|
| 52 |
return;
|
| 53 |
}
|
| 54 |
|
| 55 |
+
// Для навигационных запросов
|
| 56 |
if (event.request.mode === 'navigate') {
|
| 57 |
event.respondWith(
|
| 58 |
caches.match('/index.html').then((response) => {
|
|
|
|
| 64 |
event.respondWith(
|
| 65 |
caches.match(event.request).then((response) => {
|
| 66 |
return response || fetch(event.request).then((networkResponse) => {
|
|
|
|
| 67 |
if (requestUrl.origin === self.location.origin) {
|
| 68 |
return caches.open(CACHE_NAME).then((cache) => {
|
| 69 |
cache.put(event.request, networkResponse.clone());
|