Documentation
Documentation
The build fetches your public policy once and bundles it, so the server never fetches it at runtime.
Keep consentManifest in your Vite plugin list:
Without backendURL, the plugin reads VITE_C15T_BACKEND_URL, then
VITE_INTH_PROJECT_URL. The plugin
fetches the policy during vite build, or in vite dev when the app first
loads it, and serves it as snapshot from c15t/generated. A build fetches
only when the app uses manifest(). In src/consent.tsx, create the
provider's mode with manifest() from c15t/react instead of hosted(). It
reads the snapshot and the backend URL from c15t/generated:
Keep passing mode to ConsentProvider. The browser resolves the snapshot
without /manifest when it has the geography the policy needs, or the policy
does not depend on geography. Supply known country and region through inputs
or overrides to keep regional resolution on the snapshot.
When the build has no snapshot, as in vite dev after a failed fetch,
snapshot is undefined, and the browser fetches
${backendURL}/manifest instead.
When the required country or region is missing, the transport calls backend
/init and uses its resolved policy and translations. That response can use
newer backend policy than the build snapshot. ConsentProvider sends that
request while it first renders, before the page mounts, unless the visitor has
a stored choice.
The browser cannot guess the banner from the snapshot alone when locations
differ. With a European opt-in rule and no banner elsewhere, a banner shown
before /init answers would vanish for most of the world. The exception is a
policy whose country and region rules all show the same banner, with a default
rule that covers everywhere else: the browser resolves it at once.
Policy and resolver code are part of the browser bundle.
The snapshot is fixed at build time:
- Rebuild after changing policies, translations or vendors. If your CI caches build output, force a fresh build.
- Consent choices still go to the backend.
The build reads the backend URL from your public backend URL variable when
the config doesn't pass one: NEXT_PUBLIC_C15T_BACKEND_URL in Next.js,
NUXT_PUBLIC_C15T_BACKEND_URL in Nuxt, PUBLIC_C15T_BACKEND_URL in Astro,
Svelte and SvelteKit, and VITE_C15T_BACKEND_URL in TanStack Start and other
Vite apps. Each also reads the matching Inth variable, such as
NEXT_PUBLIC_INTH_PROJECT_URL, when the c15t one is unset. See
set the backend URL.
The fetch waits at most 10 seconds. When it fails, or no backend URL is set, every framework does the same thing:
| Command | Default when the fetch fails |
|---|---|
Production build: next build, vite build, nuxt build, astro build | The build stops with an error. |
Dev: next dev, vite dev, nuxt dev, astro dev | A warning, and the server fetches the policy at runtime. |
Set onBuildError to use one behaviour for both. 'fail' stops dev too.
'runtime' lets a production build finish, and the server fetches the policy
at runtime. The C15T_ON_BUILD_ERROR environment variable overrides the
option, so you can deploy during a backend outage without a code change:
Turborepo's strict environment mode hides undeclared variables from tasks, so
list C15T_ON_BUILD_ERROR in the build task's passThroughEnv there.
The build skips the fetch, without an error, when it can't use a snapshot,
for example when the backend URL is relative. With onBuildError: 'fail', a
relative URL stops the build. Consent modes
lists every case.
vite build and vite dev fetch the manifest when they start. vite preview
serves the last build without fetching. The plugin writes no file into your
app, so there is nothing to keep out of Git. c15t/generated ships its own
types, so tsc, vue-tsc and svelte-check pass on a fresh checkout without
a build first.
The plugin can't see the options your app passes to manifest(). When the
app passes source: 'runtime' or manifestURL, set
consentManifest({ source: 'runtime' }) too. The build then downloads no
manifest, so it doesn't fail when the backend's /manifest is down.