try to fix infinity preload
Deploy app frontend / app frontend (push) Successful in 2m45s

This commit is contained in:
2024-12-15 10:53:47 +02:00
parent bb5e58d58a
commit 3b1459cca4
2 changed files with 27 additions and 1 deletions
+17
View File
@@ -43,6 +43,15 @@ const TEMP_CACHE = new Map() // Используем карту для врем
async function handleNavigationRequest(request) {
if (TEMP_CACHE.has(request.url) && navigator.onLine) {
console.log('notifying clients about MAIN_PAGE_READY in cache')
clients.matchAll({ type: 'window' }).then((allClients) => {
allClients.forEach((client) =>
client.postMessage({
type: 'MAIN_PAGE_READY',
}),
)
})
return TEMP_CACHE.get(request.url).clone()
}
@@ -59,6 +68,7 @@ async function handleNavigationRequest(request) {
TEMP_CACHE.set(request.url, networkResponse)
// Сообщаем клиенту, что основная страница готова
console.log('notifying clients about MAIN_PAGE_READY after fetch')
const allClients = await clients.matchAll({ type: 'window' })
allClients.forEach((client) =>
client.postMessage({
@@ -114,6 +124,13 @@ async function updateStaticAssetsCache() {
self.addEventListener('message', async (event) => {
if (event.data && event.data.type === 'SKIP_WAITING') {
self.skipWaiting()
} else if (event.data && event.data.type === 'CHECK_MAIN_PAGE_READY') {
console.log('CHECK_MAIN_PAGE_READY:', TEMP_CACHE.size ? 'ready' : 'not ready')
if (TEMP_CACHE.size === 0) {
event.source.postMessage({ type: 'MAIN_PAGE_IS_NOT_READY' })
} else {
event.source.postMessage({ type: 'MAIN_PAGE_READY' })
}
} else if (event.data && event.data.type === 'CHECK_ONLINE_STATUS') {
const isOnline = navigator.onLine // Проверяем состояние сети
event.ports[0].postMessage({ online: isOnline }) // Отправляем результат обратно