W
W
webfln2019-09-25 12:37:33
caching
webfln, 2019-09-25 12:37:33

Why is the cache not being flushed in the service worker CRA?

Is anyone using CRA 3.0.0 + service workers?
I use CRA 3.1.1 and service workers.
I register like this:

worker.register({
  onUpdate: registration => {
    const waitingServiceWorker = registration.waiting;

    if (waitingServiceWorker) {
      waitingServiceWorker.addEventListener('statechange', event => {
        if (event.target.state === 'activated') {
          window.location.reload();
        }
      });
      waitingServiceWorker.postMessage({ type: 'SKIP_WAITING' });
    }
  }
});

After the update was downloaded, everything works fine on the desktop. The service worker sends SKIP_WAITTING and the page is reloaded, the cache is reset.
But smartphones have problems. For example, on Android in chrome, sometimes after updating the update pages are loaded, and sometimes the cache is dead. If we talk about PWA, then the update does not help at all there, nothing will happen until it is updated in the browser itself.
In safari, it is perfectly updated (in the browser), in PWA it is dead, only reinstallation.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question