Server-Side Utilities
Fetch consent data on the server for SSR hydration — eliminate the loading flash and improve performance.
The @c15t/react/server module provides utilities for fetching consent data on the server before rendering. This enables SSR hydration — consent state is available immediately on page load without a client-side fetch, eliminating the consent banner flash.
Info
SSR hydration is part of the initialization flow. When SSR data is available, the client skips the API fetch entirely.
Info
If you're using Next.js, the @c15t/nextjs package wraps these utilities with automatic header resolution. See the Next.js docs for framework-specific usage.
fetchSSRData
The primary function for fetching consent data on the server. It calls the c15t backend's /init endpoint with the user's request headers and returns the initial consent data.
Options
Return Value
Returns SSRInitialData | undefined. The data includes the init response (jurisdiction, translations, consent model) and GVL data when IAB is configured.
Passing SSR Data to the Provider
Pass the result as a Promise to the provider's ssrData option:
extractRelevantHeaders
Extracts geo-location and forwarding headers from the incoming request. Supports headers from Cloudflare, Vercel, AWS CloudFront, and generic proxies.
Recognized Headers
| Header | Source | Contains |
|---|---|---|
cf-ipcountry | Cloudflare | Country code |
x-vercel-ip-country | Vercel | Country code |
x-amz-cf-ipcountry | AWS CloudFront | Country code |
x-vercel-ip-country-region | Vercel | Region code |
accept-language | Browser | Language preference |
x-forwarded-host | Proxy | Original host |
x-forwarded-for | Proxy | Client IP |
normalizeBackendURL
Resolves a backend URL to an absolute URL. Absolute URLs are returned as-is. Relative URLs (starting with /) are resolved using the request's Host or Referer headers.
validateBackendURL
Validates and normalizes a URL without resolving relative paths. Useful for configuration validation.
Debugging SSR
Use the useSSRStatus hook on the client to verify SSR data was consumed: