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

261
Visualizações
PWA - How to cache html pages (not only js, css...)

If I use,

registerRoute(
    new RegExp('.*'),
    new CacheFirst({
        cacheName: 'all',
    })
);

it will work and cache all the pages with all the assets. So if I refresh the page in offline mode, it works.

But apparently it's not a good idea to cache ALL! So I want to cache js|css|eot|ttf|otf|woff|woff2 and of course the html as well.

So if I use

registerRoute(
    new RegExp('(\.(js|css|eot|ttf|otf|woff|woff2)$)'), // <<== how to add html type here to be cached?
    new CacheFirst({
        cacheName: 'all',
    })
);

and refresh the page while it's in offline mode, it can't view the page since it hasn't cached.

I'm using Vuejs, Mix, Workbox.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There are a number of different options for configuring runtime routing and caching; you can also create multiple routes with different strategies for each type of resource. Routing based on the request.destination value is a fairly robust approach.

I would avoid using a CacheFirst strategy for any URLs that are unversioned, since you don't have a great way of making sure it ever gets updated after you deploy changes. StaleWhileRevalidate or NetworkFirst is a safer strategy to use for URLs that don't contain hashes.

import {registerRoute} from 'workbox-routing';
import {StaleWhileRevalidate, NetworkFirst} from 'workbox-strategies';

registerRoute(
  // Match HTML document requests.
  ({request}) => request.destination === 'document',
  new NetworkFirst({
    cacheName: 'html',
  })
);

registerRoute(
  // Match JS, CSS, and font requests.
  ({request}) => ['font', 'script', 'style'].includes(request.destination),
  new StaleWhileRevalidate({
    cacheName: 'resources',
  })
);
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