Application file self-hosting with Cloudflare CDN
This article provides a quick guide to self-hosting the Kameleoon application file for Web Experimentation using Cloudflare CDN. Hosting the Kameleoon application file on Cloudflare can provide a noticeable performance boost by removing the additional DNS query and SSL handshake required when using the Kameleoon CDN.
kameleoon.js is deprecated and has been replaced by engine.js in all Kameleoon implementation snippets. kameleoon.js will no longer be supported after June 1st, 2026. After this date, any campaigns on websites still referencing kameleoon.js will stop functioning. Update your implementation snippet accordingly.
Setting up a worker in Cloudflare
Log in to your Cloudflare account and create a worker to point the original request back to your Kameleoon Web Experimentation snippet. You will need to configure the necessary Cloudflare route and script.
Route
Add the following path: *<your_website_url_here>/kameleoonjs/script.js.
Script
You need a script that listens for requests from the /enginejs/ route and replaces that route with the one that leads to your Kameleoon snippet.
You can use the script below, where YOUR_SITECODE must be replaced with your Kameleoon Project ID (follow the steps outlined in this article to retrieve it).
async function handleRequest(request {
const url = "https://YOUR_SITECODE.kameleoon.xx/engine.js";
return fetch(url)
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
The domain for your Kameleoon scripts (https://[your-site-code].kameleoon.xx) may vary from one project to another. Your projects may be hosted on either kameleoon.eu or kameleoon.io, depending on their creation date. Ensure you use the domain displayed in your project in the Kameleoon app.
Add the Kameleoon snippet in your source code
Refer to this article to understand how to implement Kameleoon on your website.
The final step is to replace the default Kameleoon Application JavaScript URL in the installation tag with your Cloudflare URL (eg. <your_website_url_here>/kameleoonjs/script.js if you have chosen this route). For instance, if you are using the JavaScript File (Asynchronous Loading with Anti-Flicker) implementation method, the Kameleoon application file is by default hosted on //SITE_CODE.kameleoon.io/engine.js. You just need to change this URL in the installation tag, replacing it with your own URL.