I am not a fan of JavaScript. But I already started with some Service Worker examples from Mozilla some time ago, and PWAs have proven to be very effe

A capable PWA • charlesrocket

submited by
Style Pass
2024-03-29 14:00:07

I am not a fan of JavaScript. But I already started with some Service Worker examples from Mozilla some time ago, and PWAs have proven to be very effective. So, let's go.

My first implementation was pulling cache lists from a dedicated page generated by the Zola template using a macro that pulls assets from taxonomies, pages, etc. But besides the need for filtering and discarding a lot of data, having a dedicated page for this is just ugly. That was the only way to make it work with fetch(). And I had to add an extra zola build as well.

Zola does not yet have the capability to populate non-HTML files, and I could not justify adding extra steps with NPM/etc. just for a single service worker event to function. So a new approach was needed.

Workbox or sw-tools libraries would resolve probably everything, but it's too easy. Since I would have to maintain JavaScript anyway, let's get on with it.

The solution is a cache-first service worker strategy with a fallback to offline mode. This feels like the most efficient approach. And it requires no external dependencies or extra steps. I could play with network requests, but timeout sounds too slow already, so maybe next time.

Leave a Comment