Data fetching

Practical patterns for loading data in a Next.js app (server components, route handlers, and caching).

Overview

Most Prime UI pages are server-rendered. This gives you predictable performance and simpler data loading, but you still have the option to fetch on the client when interactivity requires it.

Fetch data close to where you render it. Prefer server components for public content pages (docs/blog/changelog) and cache aggressively when results are stable.

Pick the right tool

Use this section as a quick decision guide. The table below summarizes the default choice for common scenarios.

Use caseRecommended approach
Public content pagesServer components + MDX compilation
API endpointsRoute handlers
UI that updates frequentlyClient-side fetching + caching

Next steps

Start with JSON if you are integrating a typical REST API. Add GraphQL or XML only when your product needs those formats.