Disclaimer: This website requires Please enable JavaScript in your browser settings for the best experience.

The availability of features may depend on your plan type. Contact your Customer Success Manager if you have any questions.

Dev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideLegal TermsGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev Guide

Self-host with Akamai

How to set up self-hosting with Akamai for Optimizely Web Experimentation

Self-hosting is ideal for customers who are using both HTTP/2 to serve their website and a CDN. By self-hosting, you can eliminate an SSL connection to Optimizely Web Experimentation while using multiplexing to request the snippet faster.

While self-hosting with an HTTP/1 connection may eliminate an additional DNS lookup and the SSL handshake, there is no guarantee the script will download earlier than if it was downloaded directly from Optimizely.

Use the standard snippet

See Implement the one-line JavaScript snippet to find your snippet path.

Add the self-hosted snippet

If the Optimizely snippet is installed on your page, you must remove it and replace it with the new script tag that references your self-hosting path. Add this new script tag inside the <head> tag on your page.

The snippet format should be the following:

<script src="/optimizelyjs/<your_snippet_id>.js"></script>

Replace <your_snippet_id> with the snippet ID for your project.

Example

<script src="https://cdn.optimizely.com/js/123456.js"></script>
<script src="/optimizelyjs/123456.js"></script>

Repeat this step for any additional basic snippets you may have across your site.

Add a rule to Akamai

Add a rule to your Akamai configuration. Complete this process for each standard snippet you plan to use on your site.

Add a new rule criteria

Create a criteria that applies the rule on paths that match your snippet, such as "/optimizelyjs/123456.js”. This is the path you should have included in the snippet on your site.

Add new behaviors

Add two behaviors: one targeting the origin server and one modifying outgoing request path behavior.

Set the origin server

The new origin server behavior should change the value of Origin Server Hostname to cdn.optimizely.com and set the Forward Host Header value to Origin Hostname. This modifies the request going from the CDN to the browser.

Modify outgoing request behavior

Replace part of the incoming path to ensure the request from the snippet on your page is directed to its location in Optimizely Web Experimentation.

Ensure your configurations match the following specifications:

  • Action – Replace part of the incoming path.
  • Find what/optimizelyjs/<your_project_id>.js.
  • Replace with/js/<your_project_id>.js.
  • Occurrences – All.
  • Keep the query parameters –Yes.

This behavior looks for any requests including /optimizelyjs/<your_project_id>.js and replaces that string with a new path like /js/<your_project_id>.js.

Preserve TTL settings

To ensure that Akamai respects the original TTL set in your Optimizely Web Experimentation project settings, you must create one additional behavior for caching.

Configure your caching behavior to match the following:

  • Caching Option – Honor Origin Cache-Control and Expires.
  • Force Revalidation of Stale Objects – Always revalidate with origin.
  • Default Max-age – 120 seconds (This is the default on the Optimizely CDN).
  • Honor Private? – No.
  • Honor Must-Revalidate? – No.

Match your downstream caching behavior with the following:

  • Caching Option – Allow Caching.
  • Cache Lifetime – Full edge TTL (max-age).
  • Send Headers – Send same headers as origin.
  • Mark as Private – Off.

Save this new rule. You can now use your HTTP/2 configuration to request Optimizely Web Experimentation.

Use a custom snippet

You can create a copy of the original snippet with a custom snippet. Follow Manage custom snippets with these configurations:

  • Select Create a new snippet for a single project for Type.
  • Select Include all pages from the selected project (default) to mirror your original snippet under Sources > Pages.
  • Select the Settings you chose for your original snippet.

If you already use custom snippets, you do not have to create one. Note your snippet key, as you need it later in the process.

📘

Note

Custom snippets are required due to the additional security they provide. When using a custom snippet, your snippet URL includes your Optimizely account ID. On your CDN, this verifies that all content is being served from your Optimizely account.

While in Optimizely, go to Account Settings > Plan. Find your account ID and note it, as you are going to use it later in the configuration.

Add the self-hosted snippet

If the Optimizely snippet is installed on your page, you must remove it and replace it with the new script tag that references your self-hosting path. Add this new script tag inside the <head> tag on your page.

The snippet format should be the following:

<script src="/optimizelyjs/s/<your_snippet_key>.js"></script>

Replace <your_snippet_key> with the snippet key for your custom snippet.

Example

<script src="https://cdn.optimizely.com/public/123456/s/custom.js"></script>
<script src="/optimizelyjs/s/custom.js"></script>

Repeat this step for any additional custom snippets you may have across your site.

Add a rule to Akamai

Add a rule to your Akamai configuration.

Add a new rule criteria

Create a criteria that applies the rule on paths that match your snippet, such as "/optimizelyjs/*”. This is the path you should have included in the snippet on your site.

Add new behaviors

Add two behaviors: one targeting the origin server and one modifying outgoing request path behavior.

Set the origin server

The new origin server behavior should change the value of Origin Server Hostname to cdn.optimizely.com and set the Forward Host Header value to Origin Hostname. This modifies the request going from the CDN to the browser.

Modify outgoing request behavior

Replace part of the incoming path to ensure the request from the snippet on your page is directed to its location in Optimizely Web Experimentation.

Ensure your configurations match the following specifications:

  • Action – Replace part of the incoming path.
  • Find what/optimizelyjs/.
  • Replace with/public/<your_account_number>/.
  • Occurrences – All.
  • Keep the query parameters –Yes.

This behavior looks for any requests including /optimizelyjs/ and replaces that string with a new path like /public/\<your_account_number>/.

Preserve TTL settings

To ensure that Akamai respects the original TTL set in your Optimizely Web Experimentation project settings, you must create one additional behavior for caching.

Configure your caching behavior to match the following:

  • Caching Option – Honor Origin Cache-Control and Expires.
  • Force Revalidation of Stale Objects – Always revalidate with origin.
  • Default Max-age – 120 seconds (This is the default on the Optimizely CDN).
  • Honor Private? – No.
  • Honor Must-Revalidate? – No.

Match your downstream caching behavior with the following:

  • Caching Option – Allow Caching.
  • Cache Lifetime – Full edge TTL (max-age).
  • Send Headers – Send same headers as origin.
  • Mark as Private – Off.

Save this new rule. You can now use your HTTP/2 configuration to request Optimizely Web Experimentation.