Jieiku / abridge

Fast & Lightweight Zola Theme
https://abridge.pages.dev/
MIT License
142 stars 41 forks source link

sw.min.js breaks page loading on Firefox #142

Closed gary600 closed 10 months ago

gary600 commented 10 months ago

On Firefox, the service worker created by sw.min.js completely breaks page loading, continually loading its own outdated pages from the internal cache rather than using the latest/live version of pages. Since the service worker is loaded based on the url, it even persists even after switching themes and project, which made it painful to track down what was causing it...

Jieiku commented 10 months ago

the TTL on page url cache is 24 hours. but clearing your browser cache would of coarse clear it, or if you increment the version in sw_load.js then it would invalidate the entire cache. (and load a new cache) I will add some more documentation on this, and particularly highlight that the PWA is built as a Cache first strategy (working as intended).

There is also the possibility of using a network first strategy, once I get a little free time I can create an alternate service worker for that strategy and add config options for it.

I apologize if the PWA caused ya much trouble, its a new feature and I only just recently implemented the PWA.

This explains many possible strategies (I am not using workbox though): https://developer.chrome.com/docs/workbox/caching-strategies-overview/

Jieiku commented 10 months ago

This is now resolved, this was simpler than I thought, all that was required to change it to a network first strategy was simply to set the TTL to 0. I did however test it on one of my personal sites and found that it was not working as expected initially. I fixed the paths in the node script for the output js files, and now it works perfectly. (I monitored the nginx logs and could see that it was correctly fetching the resources every time with a TTL of 0)

With a TTL of 0 it will fetch a new copy of the page every time, unless it is unable to, then it will fall back to cache. If you increase the TTL time then it becomes a cache first strategy. There are now PWA config options in the config.toml. These values only come into play when the node script is ran. (it parses these values)

zola build && npm run abridge && zola build

I added some documentation to the config.toml

Even for those that are unfamiliar with node/npm or do not want to use it, should now be able to benefit from the default PWA in abridge, because it is now default to a network first strategy.

https://github.com/Jieiku/abridge/commit/4d89eb007a635c7c3ff69e496bac71746e93e80e