What is the purpose of +page.server.js in SvelteKit?

WHAT IT TESTS: Server-only load boundaries in SvelteKit. ANSWER OUTLINE: Exclusively server-side load feeding the data prop, used for secrets like DB queries and private env vars. RED FLAG: Claiming it runs in the browser or equating it with +page.js.
WHAT IT TESTS: Understanding the split between universal and server-only load functions in SvelteKit. ANSWER OUTLINE: First, +page.server.js runs only during SSR and API requests, never in the browser. Second, it exports a load function whose return value becomes the page data prop. Third, it holds sensitive logic like direct database calls and private env vars. RED FLAG: Confusing it with +page.js, which runs on both server and client, or claiming secrets can live in universal loads.
Read the original → svelte.dev
- #sveltekit
- #routing
- #server-side-rendering
- #data-loading
- #security
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.