- Fetch the bundle once on the server.
- Pass it to the client via your framework’s data-loading mechanism.
- Initialize the client SDK with the server-provided bundle as
localConfig. - The client uses the same bundle and resolves identically — no second fetch on hydration.
SvelteKit
Layout load (server)
loadTrafficalBundle respects standard HTTP caching, so subsequent SSR requests within the cache TTL benefit from SvelteKit’s fetch cache.
Root layout (server + client)
Page
data.traffical.bundle and renders the correct variant. The client picks up the same bundle and resolves identically. No swap.
Next.js (App Router / RSC)
fetchBundle is cached via Next.js’s fetch integration; subsequent renders within the cache window don’t re-fetch.
Next.js (Pages Router)
Why this works
- Same bundle, same hash, same answer. Both server and client read the same bundle. The hashing function (
hash(unitKey + layerId) % bucketCount) is identical in@traffical/core. The same userId always resolves to the same allocation. - One network fetch. The server fetches; the client receives the bundle inline. No second fetch on hydration.
- First paint is correct. Because the server resolves before rendering, the user sees the right variant immediately. No flash of original content.
Pitfalls
- Mismatched user IDs. If the server reads
userIdfrom a session cookie but the client reads it from a different source, the two will resolve to different buckets and you’ll see a swap on hydration. Make sure both sides use the same value. - Use the SDK key on both sides. The same
traffical_sk_...SDK key (scopessdk:read+sdk:write) is browser-safe and is used both client-side in theTrafficalProviderand server-side in thefetchBundle/loadTrafficalBundlecall. There is no separate server secret for the SDK path — keep management-scoped keys out of all rendering code. - Stale bundle on long-lived pages. The client refreshes the bundle every 60s by default. SPAs running for hours will pick up new policies automatically. For static pages, a hard reload is enough.
Next steps
SSR + hydration pattern
Full end-to-end example.
React SDK
Provider, hooks, options.
Svelte SDK
Stores, context, runes.