This PR enables caching of ipfs-sw-* assets with the service worker. This will allow the service worker to cache the assets and serve them from the cache when the user is offline.
It will also allow users to load assets more quickly, and since all assets have a postfixed contenthash in their filename, we shouldn't have to worry about stale assets being served.
Also FYI: requests for ipfs-sw-sw.js (the root service worker that is registered) will not hit this cache, because service workers can't see requests for themselves.
Notes & open questions
This enables offline browsing of sites. Before this change, root assets would not be accessible if user is offline:
Title
feat: cache sw assets with service worker
Description
Fixes https://github.com/ipfs-shipyard/service-worker-gateway/issues/222
This PR enables caching of
ipfs-sw-*
assets with the service worker. This will allow the service worker to cache the assets and serve them from the cache when the user is offline. It will also allow users to load assets more quickly, and since all assets have a postfixedcontenthash
in their filename, we shouldn't have to worry about stale assets being served.Also FYI: requests for
ipfs-sw-sw.js
(the root service worker that is registered) will not hit this cache, because service workers can't see requests for themselves.Notes & open questions
This enables offline browsing of sites. Before this change, root assets would not be accessible if user is offline:
Offline with changes in
main
https://github.com/ipfs-shipyard/service-worker-gateway/assets/1173416/8ff74c8c-f141-445e-ab4d-634e6382e377
Offline with changes from this PR
https://github.com/ipfs-shipyard/service-worker-gateway/assets/1173416/777d6de8-1ee6-4ca0-8e80-afdbf8be79c6
Change checklist