- Set up CDN self-hosting using Akamai
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 a SSL connection to Optimizely 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's no guarantee the script will begin downloading earlier than if it was being downloaded directly from Optimizely.
This article walks you through the process of setting up CDN self-hosting with Akamai.
Create a custom snippet
To take advantage of CDN self-hosting, you'll need to use an Optimizely custom snippet, which is available to Enterprise-level customers.
If you're currently using the original snippet, you can create an exact copy of it using the custom snippet process. Follow the procedure described in that article, using this list of configuration options:
From the Type drop-down, select Create a new snippet for a single project.
Under Sources > Pages, select Include all pages from the selected project (default) to mirror your original snippet.
Under Settings, select the same ones you've chosen for your original snippet.
If you are already using custom snippets, you don't have to create a new one. Simply make a note of your snippet key instead, as you will need it later in the process.
Custom snippets are required due to the additional security they provide. When using a custom snippet, your snippet URL will now include your Optimizely account ID. On your CDN, this verifies that all content is being served from your Optimizely account.
While in Optimizely, navigate to Account Settings > Plan. Find your account ID and make a note of it, as you will be using it later in the configuration.
Add the self-hosted snippet
If the Optimizely snippet is already installed on your page, you'll need to remove it and replace it with the new script tag that references your self-hosting path.
If you are new to Optimizely, just add this new script tag in the appropriate spot inside the
<head> tag on your page.
The format of this snippet should be:
<your_snippet_key> is replaced with the snippet key for your custom snippet.
should now be:
Repeat this step for any additional custom snippets you may have across your site.
Add a rule to your Akamai configuration
The final step in this process is to add a new rule to your Akamai configuration. Read on to find out how.
Add a new rule criteria
First, create a new criteria that will apply the rule on paths that match
“/optimizelyjs/*”. This is the path you should have included in the new snippet on your site.
Add new behaviors
Next, add two behaviors: one targeting the origin server, and one modify outgoing request path behavior.
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 will modify the request going from the CDN to the browser.
Modify Outgoing Request Behavior
At this point, you’ll need to replace part of the incoming path, to ensure the request from the snippet on your page is directed to its location in Optimizely. Ensure your configurations match these specifications:
Action: Replace part of the incoming path
Find what: /optimizelyjs/
Replace with: /public/<your_account_number>/
Keep the query parameters: Yes
This behavior will look for any requests including
/optimizelyjs/ and replace that string with a new path, which should look like
/public/<your_account_number>. In the screenshot below, this is configured for someone whose account number is 123456.
Make sure you configure your new behavior to match the options shown above for the Action, Find what, Replace with and Occurrences fields.
TTL Setting Preservation
To ensure that Akamai respects the original TTL being set on your Optimizely project settings, you must create one additional behavior, for caching.
Your new caching behavior should be configured to match these options:
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
Your downstream caching behavior configuration options should match these:
Caching Option: Allow Caching
Cache Lifetime: Full edge TTL (max-age)
Send Headers: Send same headers as origin
Mark as Private: Off
Finally, save this new rule. You will now be able to leverage your HTTP/2 configuration to request Optimizely.
At the end of this process, your Akamai configuration options should look like this: