Server Load Functions in Svelte

From the SvelteKit cheat sheet · Data Loading · verified Jul 2026

Server Load Functions

Server-only load functions with direct database access

javascript
// +page.server.js
import { db } from '$lib/server/database';

export async function load({ params }) {
  const post = await db.post.findUnique({
    where: { slug: params.slug }
  });
  
  return {
    post
  };
}
🔒 Runs only on server with access to secrets
🗄️ Direct database access without API calls
🍪 Full access to cookies and headers
⚡ Can stream promises for faster initial render

Continue with SvelteKit

Save the full cheat sheet or work through every related task.

More Svelte tasks

Back to the full SvelteKit cheat sheet