S
Supabase•2y ago
cp-sean

When to use SvelteKit SSR vs Client queries?

Noob Alert! I'm trying to wrap my ahead around this new-to-me paradigm of querying the db directly from the client. I see in the SvelteKit tutorial in the docs that there is a helper to support SSR auth (which is being replaced by the new ssr module). But could some kind soul help me understand when it's appropriate to query directly from client vs. from +page.server.ts for example?
5 Replies
j4
j4•2y ago
That's a good question. I'm mainly a hobbiest, but I almost always grab data from the server-side. Obviously if someone was building a client-side-only app, then you'd only grab from the client. Mainly putting in my 2 cents to bump this post a little. Perhaps someone else would have a better distinction.
lecramr
lecramr•2y ago
That is also exactly my question, I come from traditional Full-Stack Apps, .Net Backend, exposes REST API, gets consumed by a Angular/React App. With Svelte I am not really sure, when to use what and how to structure the logic inside the app. Any hints?
Budi
Budi•2y ago
I would suggest reading this section of the SvelteKit docs. Client-side load functions are universal and server-side load functions are server only. SvelteKit and Vite use hot reloading, which minimizes new rendering (and db calls IIUC) unless necessary. https://kit.svelte.dev/docs/load
SvelteKit docs
Loading data • SvelteKit documentation
Budi
Budi•2y ago
I think you should generally strive to interact with the database from server-side load functions.
lecramr
lecramr•2y ago
Thank you really much! I'll dig thorugh it 🙂

Did you find this page helpful?