Svelte & SvelteKit (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
Server Load Functions (`+page.server.ts`) vs. Universal Load Functions (`+page.ts`).
senior LevelSSR & HydrationSystem Design
In Simple Words:
- Server Load (
+page.server.ts):- Runs only on the server.
- Can safely query databases directly (Prisma, PostgreSQL, MongoDB) or use private environment variables (
$env/static/private). - Serializes return data to JSON and transmits it to the client page component.
- Universal Load (
+page.ts):- Runs on the server during initial page load, but runs in the browser during client-side navigation.
- Useful for client-side API fetches or when data is already cached in memory.