-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: cache sw assets with service worker #234
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
src/sw.ts
Outdated
const isIndexHtmlRequest = url.pathname === '/' && !isSubdomainRequest(event) | ||
|
||
// if request is for https://cdn.jsdelivr.net/* we should consider it a sw asset | ||
const isJsDelivrRequest = /^https:\/\/cdn.jsdelivr.net\/.+$/.test(event.request.url) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tangentially related: what do you think about publishing the CSS as part of this app instead of relying on a third-party origin (jsdeliver).
With both Cloudflare and the SW Cache, should be performant enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea i started to do that previously and i think i squashed it because of other changes. I could do it as a part of this pr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that i'm at my laptop, I think i started to do that with the dynamic imports, but it only made the bundle larger.. now that index.ts and app.tsx is smaller, and we have a router, I could include tachyons and ipfs-css on only helper-ui, redirect-page, and config, and it will reduce burden for redirect-interstitial (ipfs first-hit without sw registered)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed by 20a9c6d
(#234)
note that because the bundle is larger now (-rw-r--r-- 1 sgtpooki 13M Apr 30 08:08 ipfs-sw-138-66da405c07a0317cdbbf.css
), there is FOUC on routing determination.
I don't think we should include it in the bundle.. but also, I think we should because then we're not dependent upon a third party.. ¯\_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lidel could use eyes on this one here.
Title
feat: cache sw assets with service worker
Description
Fixes #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 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:
Offline with changes in
main
2024-04-29.at.10.51.45.-.Brown.Rhinoceros.mp4
Offline with changes from this PR
2024-04-29.at.10.47.01.-.Lavender.Wombat.mp4
Change checklist