joystick
joystick copied to clipboard
Fix service worker error when hot reloading
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).