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
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:
This approach provides fast rendering, stable UI behavior, and full compatibility with Nuxt hydration.
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.