Encited

How to Integrate Pre-rendering with Akamai

How Akamai pre-rendering works#

An Akamai Property Manager rule sends crawler requests for public pages to Encited before they reach your origin.

Crawler GET requests for pages go to Encited. Browser traffic, assets and non-GET requests go to your origin as before. When Encited answers 304, returns an error or times out, Akamai Site Failover fetches the page from your origin.

The rule uses Property Manager behaviors only. EdgeWorkers are not used: an EdgeWorkers sub-request must go to a host served by Akamai and has a 4-second limit, which is shorter than a first render.

Prerequisites#

  • An Akamai property for your domain, and permission to edit and activate its versions.
  • The origin hostname in the property's default rule.
  • An Encited API key. You store it in a sensitive property variable, not in the rule.

Set up pre-rendering with Akamai#

1. Create a new version of the property#

In Akamai Control Center, open the property that serves your domain and create a new version. The active version stays available for rollback.

2. Add two property variables#

Under Property Variables, add:

Name Value Security setting
ENCITED_URL empty Hidden
ENCITED_API_KEY your Encited API key Sensitive

Akamai adds the PMUSER_ prefix. Save the version before you add the rule.

3. Add the Encited rule#

Add the rule below as the last entry in the children of the default rule in the property's JSON editor. A rule after it would override its origin. Replace origin.yourdomain.com with the origin hostname from your default rule.

encited-prerender

{
  "name": "Encited pre-rendering",
  "comments": "Sends crawler requests for pages to Encited. Replace origin.yourdomain.com with the origin hostname from your default rule.",
  "criteriaMustSatisfy": "all",
  "criteria": [
    {
      "name": "requestMethod",
      "options": { "matchOperator": "IS", "value": "GET" }
    },
    {
      "name": "fileExtension",
      "options": {
        "matchOperator": "IS_NOT_ONE_OF",
        "values": ["js", "mjs", "css", "map", "json", "xml", "txt", "png", "jpg", "jpeg", "gif", "webp", "avif", "svg", "ico", "pdf", "woff", "woff2", "ttf", "eot", "mp4", "webm", "mp3", "zip", "webmanifest"],
        "matchCaseSensitive": false
      }
    },
    {
      "name": "userAgent",
      "options": {
        "matchOperator": "IS_ONE_OF",
        "values": ["*Googlebot*", "*Google-InspectionTool*", "*Storebot-Google*", "*GoogleOther*", "*bingbot*", "*BingPreview*", "*DuckDuckBot*", "*DuckAssistBot*", "*YandexBot*", "*Baiduspider*", "*Applebot*", "*GPTBot*", "*ChatGPT-User*", "*OAI-SearchBot*", "*ClaudeBot*", "*Claude-User*", "*Claude-SearchBot*", "*GrokBot*", "*xAI-Grok*", "*xAI-Bot*", "*xAI-SearchBot*", "*PerplexityBot*", "*Perplexity-User*", "*meta-externalagent*", "*facebookexternalhit*", "*Twitterbot*", "*LinkedInBot*", "*Slackbot*", "*Discordbot*", "*TelegramBot*", "*WhatsApp*", "*Pinterestbot*", "*Amazonbot*", "*Bytespider*", "*CCBot*", "*cohere-ai*", "*MistralAI-User*", "*YouBot*"],
        "matchWildcard": true,
        "matchCaseSensitive": false
      }
    }
  ],
  "behaviors": [
    {
      "name": "setVariable",
      "options": {
        "variableName": "PMUSER_ENCITED_URL",
        "valueSource": "EXPRESSION",
        "variableValue": "https://{{builtin.AK_HOST}}{{builtin.AK_URL}}",
        "transform": "URL_ENCODE"
      }
    },
    {
      "name": "origin",
      "options": {
        "originType": "CUSTOMER",
        "hostname": "encited.com",
        "forwardHostHeader": "ORIGIN_HOSTNAME",
        "cacheKeyHostname": "ORIGIN_HOSTNAME",
        "httpPort": 80,
        "httpsPort": 443,
        "originSni": true,
        "verificationMode": "PLATFORM_SETTINGS",
        "compress": true,
        "enableTrueClientIp": false
      }
    },
    {
      "name": "rewriteUrl",
      "options": {
        "behavior": "REWRITE",
        "targetUrl": "/api/prerender/render?url={{user.PMUSER_ENCITED_URL}}"
      }
    },
    {
      "name": "modifyOutgoingRequestHeader",
      "options": {
        "action": "ADD",
        "standardAddHeaderName": "OTHER",
        "customHeaderName": "x-lovablehtml-api-key",
        "headerValue": "{{user.PMUSER_ENCITED_API_KEY}}"
      }
    },
    {
      "name": "modifyOutgoingRequestHeader",
      "options": {
        "action": "DELETE",
        "standardDeleteHeaderName": "OTHER",
        "customHeaderName": "Cookie"
      }
    },
    {
      "name": "modifyOutgoingRequestHeader",
      "options": {
        "action": "DELETE",
        "standardDeleteHeaderName": "OTHER",
        "customHeaderName": "Authorization"
      }
    },
    {
      "name": "modifyOutgoingRequestHeader",
      "options": {
        "action": "DELETE",
        "standardDeleteHeaderName": "OTHER",
        "customHeaderName": "x-encited-client-ip"
      }
    },
    {
      "name": "caching",
      "options": { "behavior": "NO_STORE" }
    }
  ],
  "children": [
    {
      "name": "Send crawler IP",
      "comments": "Bot requests only: Encited checks the IP against the crawler's published ranges. Browsers send Sec-Fetch-Mode, so visitor IPs are never sent.",
      "criteriaMustSatisfy": "all",
      "criteria": [
        {
          "name": "requestHeader",
          "options": { "headerName": "Sec-Fetch-Mode", "matchOperator": "DOES_NOT_EXIST" }
        }
      ],
      "behaviors": [
        {
          "name": "modifyOutgoingRequestHeader",
          "options": {
            "action": "ADD",
            "standardAddHeaderName": "OTHER",
            "customHeaderName": "x-encited-client-ip",
            "headerValue": "{{builtin.AK_CLIENT_REAL_IP}}"
          }
        }
      ]
    },
    {
      "name": "Fall back to origin",
      "comments": "Encited answers 304 when the page should come from your origin. Errors and timeouts also fall back.",
      "criteriaMustSatisfy": "any",
      "criteria": [
        {
          "name": "matchResponseCode",
          "options": { "matchOperator": "IS_NOT_ONE_OF", "values": ["200", "301"] }
        },
        {
          "name": "originTimeout",
          "options": { "matchOperator": "ORIGIN_TIMED_OUT" }
        }
      ],
      "behaviors": [
        {
          "name": "failAction",
          "options": {
            "enabled": true,
            "actionType": "RECREATED_CEX",
            "cexHostname": "origin.yourdomain.com",
            "cexCustomPath": false
          }
        }
      ]
    }
  ]
}

The rule does these steps:

  1. Matches GET requests from known crawlers that do not ask for a static file.
  2. Sets PMUSER_ENCITED_URL to the URL-encoded public URL.
  3. Removes the Cookie and Authorization headers, then sends the request to encited.com/api/prerender/render with your API key in the x-lovablehtml-api-key header.
  4. For bot requests (no Sec-Fetch-Mode header), sends the visitor IP in the x-encited-client-ip header, so Encited can check the crawler against its published IP ranges. Browser visitors' IPs are never sent.
  5. Turns off Akamai caching for these responses. Encited keeps its own snapshot cache.
  6. Fetches the page from your origin when Encited answers with anything other than 200 or 301, or times out.

If you use Akamai Bot Manager, you can replace the userAgent match with a match on Bot Manager's search engine and AI crawler categories.

4. Test on staging, then activate#

Activate the version on the Akamai staging network. Point your domain at a staging edge IP in your hosts file, then request a page as Googlebot:

curl -s -D - -o /dev/null -A "Googlebot" https://yourdomain.com/ | grep -i x-lovablehtml

A pre-rendered page has the x-lovablehtml-render-cache header. Request the same page with a browser User-Agent: it must not have the header. When both tests pass, activate the version on production.

5. Check the connection in Encited#

Open the setup page for your domain in Encited and click Check Connection. You can also confirm a bot received your rendered content.

Troubleshooting#

  • Crawlers get an empty 304 or an Encited error. The failover rule is missing, or it is not a child of the Encited rule. Check that cexHostname is your origin hostname.
  • Check Connection fails and crawlers get the origin page. PMUSER_ENCITED_API_KEY is empty or holds a revoked key. Check your keys under Settings → API keys.
  • The domain is not in your Encited workspace. Add it before you activate the rule. Akamai must send your public hostname in PMUSER_ENCITED_URL, not the origin hostname.
  • A crawler is not matched. Add its User-Agent token to the userAgent values, with * on each side.

For help, email team@encited.com.