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

130
Visualizações
Safari does not update cache in adjacent tabs when a new service worker is released

I am using worbox and I ran into a problem. After assembling the files, I execute injectManifest to generate the pre-cached files. Also, I have different strategies for different types of files. I notify users to install a new version via a popup with a confirm button and this works great in chrome. You confirm the installation, through postMessage I send a message and all the tabs are reloaded and the cache is updated. But in safari this does not work, in the same way the tabs are reloaded, but the cache is updated only in 1 tab, in all the others it remains old and so that I do not do the only thing that helps is a closed browser or manually resetting the cache, in all subsequent tabs that I open the cache is updated.

Sample code with installation of a worker and subsequent notification for installation

import {Workbox} from 'https://storage.googleapis.com/workbox-cdn/releases/6.4.2/workbox-window.prod.mjs';

if ('serviceWorker' in navigator) {
    const wb = new Workbox('/pwabuilder-sw.js');
    
    let refreshing;
    navigator.serviceWorker.addEventListener('controllerchange', (event) => {
        if (refreshing) return
        refreshing = true
        window.location.reload()
    });

    const showSkipWaitingPrompt = (event) => {
        document.querySelector('.notification-install-sw').classList.add('show');
        document.getElementById('reload').addEventListener('click', function(e){
            wb.messageSkipWaiting();
            document.querySelector('.offline-with-cache-notification').style.display = 'none';
        });

    };

    wb.addEventListener('waiting', showSkipWaitingPrompt);

    wb.register();
}


if (!navigator.onLine) {
    document.querySelector('.offline-with-cache-notification').classList.add('show');
}

And example code from the worker file itself

importScripts('https://storage.googleapis.com/workbox-cdn/releases/6.4.2/workbox-sw.js');


workbox.googleAnalytics.initialize();


const STYLE_CACHE = "stylesheets";


self.addEventListener('message', (event) => {
    if (event.data && event.data.type === 'SKIP_WAITING') {
        self.skipWaiting();
    }
});

workbox.core.clientsClaim();


// Clean Up Old Precaches
workbox.precaching.cleanupOutdatedCaches();

workbox.precaching.precacheAndRoute(self.__WB_MANIFEST);


workbox.routing.registerRoute(
    ({request, url}) =>
        request.destination === "style",
    new workbox.strategies.StaleWhileRevalidate({
        cacheName: STYLE_CACHE,
        plugins: [
            new workbox.cacheableResponse.CacheableResponsePlugin({
                statuses: [200]
            }),
            new workbox.expiration.ExpirationPlugin({
                maxEntries: 15,
                maxAgeSeconds: 30 * 24 * 60 * 60, // 30 Days
                purgeOnQuotaError: true,
            }),
        ],
    })
)
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