Description
Describe the problem
Currently, it is difficult to do “offline first” in SvelteKit. If you want to bring a page from the cache instead of going over the web (especially in cases where the web is unavailable), you can only provide responses for when the server was pinged, with the server’s SSR instead of your own. With Kit’s client-side routing, it is unknown if a site will even be loaded at all.
Using Workbox would help, but that still doesn’t solve the problem of serving dynamic svelte content to users from a service worker.
Describe the proposed solution
The proposed solution would be to export new functionality to the service workers, such as “render_page”, which will look up the corresponding URL in an internal dictionary and perform SSR rendering with required props.
Another solution to this issue would be to expose more metadata, and a CSR html template, to the service worker. It’d have the same effect while being smaller and more flexible, and probably much easier to implement. This would be a great solution as well, as it’s probably faster do to CSR once than to do SSR and then hydrate it.
This would enable offline-first usage at high scale. A good example would be a storefront—it’s much more efficient to cache some JSON data of all products than to store all of the HTML for a single product.
Alternatives considered
Initially, I considered doing some voodoo magic to create an HTML template which would work to perform CSR upon loading in an offline situation, but this proved to be extraordinarily difficult, as it is hard to tell which Vite bundles are needed per-page with the information provided (not that you can’t find a way to do it…)
I’ve also tried caching the SSR pages, but again, it is a lot of content, and wouldn’t be readable eg. For a storefront or blog.
Importance
nice to have
Additional Information
No response