Skip to main content

Documentation

Documentation

The build fetches your public policy once and bundles it, so the server never fetches it at runtime.

Install c15t alongside @c15t/browser for the build plugin. Add it to your existing Vite plugins:

vite.config.ts (plugins option)
import { consentManifest } from 'c15t/build';

export default {
	plugins: [
		// Keep your existing framework plugins here.
		consentManifest({ backendURL: 'https://your-project.inth.app' }),
	],
};

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 your browser entry point, pass manifest() as the mode of the existing init() call. It reads the snapshot and the backend URL from c15t/generated:

src/main.ts
import { init, manifest } from '@c15t/browser';

init({ mode: manifest() });

Keep your scripts and UI options. The browser resolves the snapshot without a manifest request when the policy does not need geography, or the required country and region are known through overrides. When required geography is missing, it calls backend /init and uses the backend's resolved policy and translations. Those visitors still wait for a backend round trip and can receive newer policy than the build 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.

A script-tag site without a build step cannot run this hook.

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:

CommandDefault when the fetch fails
Production build: next build, vite build, nuxt build, astro buildThe build stops with an error.
Dev: next dev, vite dev, nuxt dev, astro devA 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:

C15T_ON_BUILD_ERROR=runtime npm run build

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.

For policy updates without a rebuild, use hosted(), which asks the backend's /init on each page load, or manifest({ source: 'runtime' }), which fetches the manifest at runtime. Both keep reading the backend URL from the plugin.