Introducing #ProjectServiceWorker

I believe every web app should be able to work offline and I have made it my mission to get people to implement offline support for their web apps.

To do this, I implemented a basic Service Worker that you can add to your web app to make it work offline.

Grab it here, add it to your web app, and comment with a link here (or in a separate post) using #ProjectServiceWorker

I will repost each one.

Grab it here 👇
https://github.com/DannyMoerkerke/basic-service-worker

GitHub - DannyMoerkerke/basic-service-worker: A basic Service Worker to make your web app work offline

A basic Service Worker to make your web app work offline - DannyMoerkerke/basic-service-worker

GitHub
@dannymoerkerke that's very detailed! Thank you for sharing it.

@dannymoerkerke Do you know of any resources that talk about how to download an entire website for offline use?

For example, I was working on something recently and they wanted users to be able to download megabytes of static content ahead of time before going offline (similar to Netflix, I guess).

My initial thought was to just have a button that ran all of the requests to the resources in the background secretly.

(I ended up just optimizing for “low connection mode” like you describe here.)

@dannymoerkerke Nice! What would you say is the difference between using this and something like Google's Workbox?

Also, I wonder if it would be worth changing references to "its cache" to "the cache" - am I wrong to think that you just access the normal storage APIs from the SW? And, related, what do you think of using IndexedDB instead of the Cache API?

@nickchomey sorry for the very late reply, haven’t been very active here lately. The difference between Workbox and basic-service-worker is that it’s much smaller and only focused on making your web app work offline. I usually only use IndexedDB to store requests while offline for retry. I don’t see any benefit of using it for responses instead of the cache since the latter is easier to work with and probably optimized for fast read and write.