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

132
Visualizações
Firebase PWA service worker page not working

So the problem we are currently facing is that only some pages can be accessed in an offline connection, some cannot be accessed and return to the main page, namely Dashboard Page. We follow the guide from 'https://developers.google.com/web/fundamentals/primers/service-workers' in registering service workers and registering them as importScript in 'https://pwa.nuxtjs.org/workbox' module.

Here is our custom-sw.js Code:

var CACHE_NAME = "cache-v2";
var urlsToCache = ["index.html"];

self.addEventListener("install", function (event) {
  event.waitUntil(
    caches.open(CACHE_NAME).then(function (cache) {
      console.log("Opened cache");
      return cache.addAll(urlsToCache);
    })
  );
});

self.addEventListener("activate", function (e) {
  console.log("[ServiceWorker] Activate");
  e.waitUntil(
    caches.keys().then(function (keyList) {
      return Promise.all(
        keyList.map(function (key)
 {
          if (key !== CACHE_NAME) {
            console.log("[ServiceWorker] Removing old cache", key);
            return caches.delete(key)
;
          }
        })
      );
    })
  );
  return self.clients.claim();
});

self.addEventListener("fetch", function (event) {
  event.respondWith(
    caches.open(CACHE_NAME).then(async function (cache) {
      const response = await cache.match(event.request);
      console.log("SERVICE WORKER: ", event.request);
      var fetchPromise = fetch(event.request)
        .then(function (networkResponse) {
          cache.put(event.request, networkResponse.clone());
          return networkResponse;
        })
        .catch((err) => {
          console.log("ERROR WHILE FETCHING: ", err.message);
          return response;
        });
      return response || fetchPromise;
    })
  );
});

and Here is our pwa module in nuxt.config.js:

pwa: {
// disable the modules you don't need
meta: { author: "PocketAngler Ltd" },
// if you omit a module key form configuration sensible defaults will be applied
manifest: {
  name: "PocketAngler Platform",
  short_name: "PocketAngler",
  display: "standalone",
  lang: "en",
},
icon: {
  source: "/favicon.png",
  fileName: "favicon.png",
  sizes: [64, 120, 144, 152, 192, 384, 512],
},
workbox: {
  importScripts: ["custom-sw.js"],
  // by default the workbox module will not install the service worker in dev environment to avoid conflicts with HMR
  // only set this true for testing and remember to always clear your browser cache in development
  dev: process.env.NODE_ENV !== "production",
},
 generate: {
   fallback: true,
 },
},

Can we get the solve for this one? We need open all page in offline mode

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