Regions v0.1.0

Strategy Comparison

Choose the right approach for your use case. All three strategies are type-safe and flexible.

Quick Decision Matrix

Use CaseRecommended StrategyWhy
Page titles, meta tagsLoad FunctionSEO, zero layout shift
Breadcrumbs, navigationLoad FunctionServer-rendered, always visible
Simple header/footer contentComponent WrapperClean API, easy to use
Action buttons with handlersSnippetAccess to page state/handlers
Forms, counters, togglesSnippetReactive, interactive UI
Dashboard statsSnippetReal-time updates, state access

The Three Strategies

1. Load Function (SSR)

Return region data from your page's load function. Best for SEO and server-side rendering.

+page.server.ts
Loading...

Note: Also works in +layout.server.ts files. See Advanced Patterns for layout-level regions and inheritance.

Best For:

  • • SEO-critical content
  • • Page titles and meta tags
  • • Breadcrumb navigation
  • • Zero layout shift
  • • Server-side data fetching

Limitations:

  • • Can't access page state
  • • No reactive updates
  • • Data must be serializable
View Examples →

2. Component Wrapper (Client-Side)

Use a wrapper component with props. Simple, clean API that works like any Svelte component.

+page.svelte
Loading...

Best For:

  • • Simple, static content
  • • Client-only pages
  • • Rapid development
  • • Clean, prop-based API
  • • Generated with CLI

Limitations:

  • • Client-side only (no SSR)
  • • Not ideal for SEO
  • • Requires separate files
View Examples →

3. Snippet (Maximum Flexibility)

Define snippets inline with full access to page state. Perfect for interactive UIs.

+page.svelte
Loading...

Best For:

  • • Interactive UI (forms, counters)
  • • Access to page state
  • • Event handlers from page
  • • Real-time updates
  • • Maximum flexibility

Limitations:

  • • Client-side only
  • • More complex setup
  • • TypeScript only (no runtime validation)
View Examples →
You can mix strategies! Use load functions for SEO content, component wrappers for simple regions, and snippets for interactive UI. All three work together seamlessly.

Decision Flowchart

START

Does this content need to be in the initial HTML (SEO)?

↳ YES

Use Load Function - Server-rendered, SEO-friendly

↳ NO

Does it need access to page state or handlers?

↳ YES

Use Snippet - Full state access, maximum flexibility

↳ NO

Use Component Wrapper - Simple, clean API

Real-World Examples

E-Commerce Product Page

  • Load Function: Product title, meta description, breadcrumbs
  • Component Wrapper: Related products sidebar
  • Snippet: Add to cart button, quantity selector

Blog Post

  • Load Function: Post title, author, publish date, meta tags
  • Component Wrapper: Table of contents, author bio
  • Snippet: Like button, comment form

Dashboard

  • Load Function: Page title, breadcrumbs
  • Snippet: Real-time stats, filter controls, action buttons

Performance Comparison

MetricLoad FunctionComponent WrapperSnippet
Initial Paint
SEO
Interactivity
Developer Experience

Next Steps