joystick icon indicating copy to clipboard operation
joystick copied to clipboard

Fix service worker error when hot reloading

Open rglover opened this issue 3 years ago • 0 comments

The service worker example included in /public occasionally throws a fetch error when it tries to load something from the cache while the server is restarting after a build. Need to refactor this so that it's aware of server availability before trying to do this.

self.addEventListener("fetch", (event) => {
  event.respondWith(
    caches.match(event.request).then((response) => {
      return response || fetch(event.request);
    })
  );
});

The fetch(event.request) here is what fails w/ a "Failed to fetch" error if the server is unavailable (makes sense).

rglover avatar May 24 '22 15:05 rglover