What is a SvelteKit load function?
Answer
A load function in SvelteKit fetches data needed for a page before it renders. Export a load function from +page.js (runs on client and server) or +page.server.js (runs only on server). The data returned is available in the page as the data prop. +page.server.js: export async function load({ params, fetch }) { const post = await fetch(\`/api/posts/\${params.slug}\`); return { post: await post.json() }; }. +page.svelte: <script> export let data; </script> <h1>{data.post.title}</h1>. Server load functions run on the server (can access databases, read files, use private environment variables) and their data is serialized and sent to the client. They also run during navigation — SvelteKit calls them before transitioning to preserve the SPA feel while loading fresh data.