Universal Load Functions in Svelte

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

Universal Load Functions

Load functions that run on both client and server

javascript
// src/routes/blog/[slug]/+page.js
export async function load({ params, fetch }) {
  const res = await fetch(`/api/posts/${params.slug}`);
  const post = await res.json();

  return {
    post,
    title: post.title
  };
}

// src/routes/blog/[slug]/+page.svelte
<script>
  let { data } = $props();
</script>

<h1>{data.title}</h1>
🔄 Runs on the server first, then in the browser
🎯 Use the fetch passed to load for relative URLs and cookies
📦 Can set response headers and dependencies
⚡ Automatic type safety with TypeScript

Continue with SvelteKit

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

More Svelte tasks

Back to the full SvelteKit cheat sheet