Documentation Index
Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
Use this file to discover all available pages before exploring further.
Implementation with SvelteKit
Integrate Kameleoon Web Experimentation with anti-flicker protection and execute theengine.js script after SvelteKit hydration. This setup ensures optimal performance, visual stability, and compatibility with the SvelteKit rendering lifecycle.
Access the production-ready SvelteKit integration
Access the production-ready repository here: https://github.com/Kameleoon/setup-engine-sveltekit Before starting, replace the sitecode value insrc/lib/integrations/Kameleoon/sitecode.ts.
Script Domain
Your Kameleoon script domain may differ between projects. Depending on when you created your project, your scripts may reside onkameleoon.eu or kameleoon.io. Always use the domain displayed for your project in the Kameleoon App.
Overview
- Preload the Kameleoon engine: Ensure the browser downloads and caches the engine early.
- Apply anti-flicker CSS: Hide content until the engine is ready to prevent layout shifts.
- Run the engine after hydration: Execute the script after SvelteKit hydration to avoid mismatches.
Components
The integration uses two components to ensure smooth loading and prevent flickering during hydration.1. Server component
The component:- Injects anti-flicker CSS during SSR to prevent UI flashing.
- Preloads the
engine.jsfile so downloading starts as soon as possible.
KameleoonHead.svelte on GitHub.
2. Client component
The component:- Removes the anti-flicker styles after hydration.
- Loads the Kameleoon
engine.jsscript dynamically. - Ensures the script loads without blocking rendering.
KameleoonHydrationReady.svelte on GitHub.
The default anti-flicker timeout is
750 ms. Adjust kameleoonLoadingTimeout if needed.Usage in RootLayout
Combine both components in your layout:layout.svelte on GitHub.
Key Takeaways
- Protect against flickering on SSR.
- Use hydration-aware script execution.
- Load the engine asynchronously.
- Use a fallback timeout for reliability.
- Avoid blocking scripts.
- Support SvelteKit layouts, SSR, and client-side routing.