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 Nuxt
Integrate Nuxt 4 with Kameleoon Web Experimentation. This guide covers the steps to preload the Kameleoon engine with anti-flicker protection and execute theengine.js script after client hydration. This setup ensures optimal performance, visual stability, and compatibility with the Nuxt rendering lifecycle.
Access reference implementations for:
Access the production-ready Nuxt 4 integration
Find the production-ready repository here: https://github.com/Kameleoon/setup-engine-nuxt-4 Before starting, replace the sitecode value inintegrations/Kameleoon/sitecode.ts.
Depending on when you created your Kameleoon project, your scripts may reside on
kameleoon.eu or kameleoon.io. Always use the domain from your project settings in the Kameleoon App.Overview
Workflow
| Phase | Description | Component |
|---|---|---|
| SSR Rendering | Inject the preload link and anti-flicker CSS | KameleoonHead.vue |
| Client Hydration | Vue hydrates the DOM | — |
| Post Hydration | Load the Kameleoon engine asynchronously | KameleoonScriptLoader.client.vue |
| Fallback Safe-Exit | Remove anti-flicker CSS if the script fails or stalls | KameleoonScriptLoader.client.vue |
Quick setup
- Add the
integrations/Kameleoonfolder to your Nuxt project. - Import and register both integration components in your layout (we recommend
layouts/default.vue). See: Usage indefault.vue.
Components
The integration uses two Vue components executed at different stages of the Nuxt rendering pipeline:| Component | Execution Context | Purpose |
|---|---|---|
KameleoonHead.vue | Server-side (SSR) | Injects the preload directive and anti-flicker CSS before hydration |
KameleoonScriptLoader.client.vue | Client-side (post hydration) | Loads the engine script and manages the anti-flicker timeout |
1. KameleoonHead.vue
KameleoonHead.vue runs only during server-side rendering. It prepares the page for a flicker-free experience by:
- Injecting anti-flicker CSS during SSR.
- Preloading the Kameleoon engine (
engine.js) so the browser fetches it early.
KameleoonHead.vue on GitHub.
2. KameleoonScriptLoader.client.vue
KameleoonScriptLoader.client.vue executes on the client after hydration.
The component:
- Removes the anti-flicker stylesheet when the page is ready.
- Loads the
engine.jsscript dynamically. - Handles timing and fallback behavior for slow script loading.
KameleoonScriptLoader.client.vue on GitHub.
The default anti-flicker timeout is
750 ms. Adjust kameleoonLoadingTimeout as needed.Usage in default.vue
Use the following example to combine components in your layout:
default.vue on GitHub.
Key takeaways
- Prevent hydration mismatch warnings.
- Ensure a flicker-free experience before Kameleoon initialization.
- Load the script only once, including during SPA navigation.
- Maintain compatibility with layouts, pages, dynamic routes, and conditional rendering.