Precache service worker
Is there any way to implement service worker for content precaching?
For context I'm creating a website with a midi player. It would be great to precache large (1 to 21 MB ish) SoundFont files.
I've tried using VitePWA plugin in Vinxi. It doesn't appear to register any service workers though.
app.config.ts:
9 Replies
i was looking for that the other day but couldn't find anything either, so i wrote my own rollup plugin to get the job done: https://github.com/bigmistqke/repl/tree/main/src/plugins/rollup-service-worker mb u can adapt this to ur needs
GitHub
repl/src/plugins/rollup-service-worker at main · bigmistqke/repl
🗒️ Unstyled building blocks to compose typescript playgrounds ⚡ Powered by solid-js with integrations for monaco-editor. - bigmistqke/repl
haven't checked out if it works with
solid-start
tho, just regular vite project.Fascinating. I guess worst case scenario, I'll have to write it directly into html or separate ts file
yes exactly
that's basically what the plugin does
1 other aspect that is critical is that the location of the service-worker is in the root of the build.
Yeah, otherwise the precaching doesn't work properly?
yes exactly
i didn't know personally 🙂
was really surprised by that fact
I ran into that problem once with an astro and solid js app
Honestly I think it makes more sense to only use one framework
ye, it's like something you have to figure out by doing it wrong first. very unintuitive. i suppose it is a security measure or something
true, astro s cool tho.
As a basic solution this is what I have in the
sw.js
file in public
The service worker can be loaded in entry-client.tsx
As for busting previous cache versions in sw.js
Unfortunately this is quite verbose. The ideal solution would probably be some sort of Vinxi
plugin with Workbox
solution