DEV Community


Posted on

Service Workers... aren't working

Well, I know there are articles all over the internet that talk about service workers. However, I'm stuck.

I'm trying cache a few files for offline use, for a small game I'm working on, which I would've thought would be relatively simple. Previous versions of it used <html manifest="cache.manifest"> to cache the files necessary, and I had planned to do the same once again... until I did a bit of research, and found it was deprecated.

Service workers are, apparently, the recommended replacement for the appcache. For some reason, I can't get them working, though. I've tried following the instructions for making a web-app work offline with service workers off the MDN web docs, but I keep getting Uncaught (in promise) TypeError: Request failed in the console.

Help would be much appreciated.

View the game @
View the source code @!/car-cricket

Discussion (4)

usamaashraf profile image
Usama Ashraf

assets/cricket.png doesn't seem to valid since I'm getting a 404 on hitting

It's good to catch these kinds of errors too:

     .then(() => console.log('Assets added to cache'))
     .catch(err => console.log('Error while fetching assets', err));

Also, addAll won't cache any of the specified assets if even one request fails.

dragonwocky profile image
dragonwocky Author

Ah, thanks. That's fixed the error, but I still can't access the site offline. On mobile, it just shows the "no internet" page, and on computer I either get no errors or I get An unknown error occurred when fetching the script.
Failed to load resource: net::ERR_INTERNET_DISCONNECTED

usamaashraf profile image
Usama Ashraf

See if this helps.

meduzen profile image
Mehdi M. • Edited on

There’s just no (look in, that’s why the Service Worker can’t cache it.

However, this file URL is, so even with the fixed URL, it won’t be cached because Service Worker can’t cache external resources, if I’m correct.