Add local SSR/CSR to Service Workers.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are identified. Start by reviewing the existing service-worker integration and the SSR, CSR, and client-side-routing behavior described in the issue; done would require an agreed design for offline dynamic page rendering and its implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100