> ## 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.

# Application file self-hosting with Fastly CDN

> Self-host the Kameleoon application file on Fastly CDN to reduce DNS latency and SSL handshake overhead compared to using the default Kameleoon CDN.

> [!NOTE]
>
> Kameleoon has deprecated `kameleoon.js` and replaced it with `engine.js` in all Kameleoon implementation snippets. Kameleoon will no longer support `kameleoon.js` after **October 1, 2026**. After this date, any campaigns on websites still referencing `kameleoon.js` will stop functioning. Update your implementation snippet accordingly.

## Fastly configuration

Log in to your Fastly account and create an origin host and two content headers as follows:

### Create the origin host

1. Navigate to the tab `Service configuration` and click the left entry `Origins > Hosts`. Click `Create host` and create a new condition to target your Kameleoon application file. Give it a descriptive name, such as **Kameleoon JavaScript application file**.
2. In the Apply if box, provide this condition `req.url ~ "^/kameleoon/engine.js"`
3. Save your new condition to apply it to your new origin host.
4. Apply the following configuration parameters to your origin host, replacing `YOUR_SITECODE` with your Kameleoon Project ID (follow the steps outlined in this [article](https://docs.kameleoon.com/user-manual/project-management/manage-your-projects.md#how-do-i-find-my-sitecode) to retrieve it):

* **Name**: YOUR\_SITECODE.kameleoon.io
* **Address**: YOUR\_SITECODE.kameleoon.io
* **Certificate hostname**: YOUR\_SITECODE.kameleoon.io

![Origin host configuration](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/fastly-origin-host.png)

> [!NOTE]
>
> Note: The domain for your Kameleoon scripts may vary from one project to another. Your projects may use either `kameleoon.eu` or `kameleoon.io` depending on their creation date. Make sure you use the domain displayed in your project in the Kameleoon App.

### Create the headers

You need to create headers to specify how you want content served to your users from your website:

1. Click the left entry `Content > Headers`. Click `Create a header`.
2. Attach the same condition you built for the host to target the new Kameleoon JavaScript application file on your site.
3. Give your header a name (for example, YOUR\_SITECODE.direct.kameleoon.io host) and configure it as follows, replacing `YOUR_SITECODE` with your Kameleoon Project ID.

* **Type / Action**: Request - Set
* **Destination**: http.Host
* **Source**: "YOUR\_SITECODE.direct.kameleoon.io"

4. Click Create to save your header.

![Header 1 configuration](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/fastly-header-1.png)

Before activating your new configuration, you need to create a second header to modify the base of the request

1. Click `Create a header`
2. Attach the same condition you built for the host to target the new Kameleoon JavaScript application file on your site.
3. Give your header a name (for example, YOUR\_SITECODE.direct.kameleoon.io base) and configure it as follows, replacing `YOUR_SITECODE` with your Kameleoon Project ID.

* **Type / Action**: Request - Regex
* **Destination**: url
* **Source**: req.url
* **Regex**: ^/kameleoon/engine.js
* **Substitution**: /engine.js?uncompressed=true

4. Click Create to save your header.

![Header 2 configuration](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/fastly-header-2.png)

### Select compression format

To enable compression, start by selecting a compression format using the steps below:

1. Click the left entry `Content`.
2. Scroll to the Compression area. The Compression controls appear.
3. Select `Use Brotli compression when available` to use Brotli compression by default for browsers that support it.

![Compression configuration](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/fastly-compression.png)

> [!NOTE]
>
> Remember to activate your new Fastly configuration to allow it to take effect before updating your source code.

## Add the Kameleoon snippet in your source code

> [!NOTE]
>
> Refer to this [article](https://docs.kameleoon.com/developer-docs/web-experimentation/implementation-and-deployment/standard-implementation.md) to understand how to implement Kameleoon on your website.

The final step is to replace the default Kameleoon application file URL in the installation tag with your Fastly URL. For instance, if you are using the JavaScript File ([Asynchronous Loading with Anti-Flicker](https://docs.kameleoon.com/developer-docs/web-experimentation/implementation-and-deployment/standard-implementation.md#asynchronous-tag-without-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 Fastly URL.
