Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
Offline mode for service worker still fetches from server using Chrome offline mode

I am learning about PWAs/service workers and most tutorials either use the offline mode in the application or network tab to toggle the online state. They seem to have no issues yet when I toggle it offline, my service worker is still fetching from the server. The only true way I can get my fallback HTML to load is to stop my express server. I have also tried without any node environment and use live-server as a vscode extension but that too gives me the same result. I have to stop the live-server for it to realize I'm offline.

I've checked my fetch event code in sw.js which matches the tutorial so I don't see any reason for it not to work like others.

// fetch event
self.addEventListener('fetch', function onFetchReceived(evt) {
  // console.log(`Fetch event received`, evt);
  evt.respondWith(
    caches.match(evt.request).then(function fulfilled(cacheResponse) {
      return (
        cacheResponse ||
        fetch(evt.request)
          .then((fetchResponse) => {
            console.log('not found in cache, getting from server');
            return caches.open(dynamicCacheName).then((cache) => {
              cache.put(evt.request.url, fetchResponse.clone());
              return fetchResponse;
            });
          })
          .catch(() => {
            console.log('offline, unable to retrieve from server.');
            return caches.match('/pages/offline.html');
          })
      );
    })
  );
});
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda