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

172
Visualizações
Service Worker's fetch event Doesn't fire after service worker registration

I'm new to Service Worker, I tried to write some code to learn how to use Service Worker in My Next.js Application but found some problems with fetch event handler, for some reason fetch event handler doesn't run when registering the service worker for the first time but when i just refresh the page the event handler works just fine and i don't know why , this my app's public folder structure:

/public
    /assets
    /icons
    manifest.json
    service-worker.js
    service-worker-registration.js

manifest.js:

{
  "name": "FakeHulu",
  "short_name": "FakeHulu",
  "description": "My Own version of Hulu",
  "icons": [
    {
      "src": "/icons/manifest-icon-192.maskable.png",
      "sizes": "192x192",
      "type": "image/png",
      "purpose": "any"
    }, ...

  ],
  "theme_color": "#ffffff",
  "background_color": "#ffffff",
  "start_url": "/",
  "display": "fullscreen",
  "orientation": "portrait"
}

service-worker-registration.js:

if("serviceWorker" in navigator){
    window.navigator.serviceWorker.register("/service-worker.js", { scope: '/' }).then(sw => console.log("serviceWorker Supported and register"))
}

service-worker.js:

self.addEventListener("install" , evt => {
    evt.waitUntil(caches.open("main_cache").then(cache => cache.addAll(["/", "/something"])));

    self.skipWaiting();
});

self.addEventListener("activate" , evt => {
    console.log(evt);
    clients.claim();
});

self.addEventListener("fetch" , evt => {
    console.log(evt);
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

On your fist load the order of operation is this:

  1. Download the client page.
  2. Find the the sw registration in the client page and download it.
  3. Install the service worker.

Notice that there's no fetch() handler to run when your client and service worker are downloaded because the service worker hasn't been installed yet.

On reload the order is this:

  1. Refresh the page.
  2. The Fetch() handler in the existing service worker intercepts the request and decides whether to retrieve the requested resource from a local resource or from the network.
about 4 years ago · Juan Pablo Isaza Relatório
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