Cloudflare edge Worker
How it works
What the Worker does with each request, how long it waits, what it caches and what it sends to Aiptimise.
Modes#
The effective mode is the lower of the Worker's AIPTIMISE_MODE and your site's mode in Aiptimise, in the order off < shadow < on.
| Mode | Pages | Calls to Aiptimise |
|---|---|---|
off | Passed through unchanged. | None, when set on the Worker. |
shadow | Passed through unchanged. | Documents are looked up and each page is logged with what would have been added. |
on | JSON-LD blocks added where Aiptimise has a document. | As in shadow. |
Which requests it touches#
- Only
GETrequests for hostnames and paths Aiptimise lists for your site. Other hostnames, excluded paths, other methods and static assets (by file extension) pass straight through with no call. - The Worker fetches your page from your origin as usual, in parallel with its lookup. Only
200responses with atext/htmlcontent type are rewritten; everything else is returned as your origin sent it. - On a rewritten page the body changes, so the Worker drops
ETag,Last-ModifiedandContent-Length. All other headers are kept.
Caching and timing#
The Worker reads three things from Aiptimise and keeps them in Cloudflare's cache in each data center. They come first from the Aiptimise edge API (edge.aiptimise.com, on Cloudflare's network); if it has not answered within 300 ms, or answers with an error, app.aiptimise.com is asked too.
| What | Kept | Notes |
|---|---|---|
| Site settings: hostnames, excluded paths, crawler list, wait times | An hour, then refreshed in the background | |
| Site mode | 60 seconds | If Aiptimise cannot be reached, the last known mode is kept for 15 minutes; after that nothing is added until it answers again. |
| A page’s document | An hour, then served while it is rechecked, for up to 7 days | Content changes in Aiptimise reach active data centers within about a minute. A page with no document is remembered too. |
When a document is cached, it is added at once. When it is not, the end of the page waits up to 1.2 seconds for AI crawlers and 300 ms for everyone else; a later answer still fills the cache for the next request. Measured on a warm cache, the Worker adds a few milliseconds to the time to first byte.
Failure behavior#
- Any error, timeout or unexpected answer from Aiptimise: the page goes out complete and unchanged.
- If Aiptimise rejects the Worker's signature (a wrong or rotated secret), the Worker treats your site as
off. - The Cloudflare daily request limit with the route failing open: requests go to your origin without the Worker.
What each request sends#
After the response has gone out, the Worker sends one signed record per page request to Aiptimise: the URL, method, User-Agent, Referer, Accept-Language, the visitor's IP address, Cloudflare's country, data center, network (ASN) and verified-bot category, and what the Worker did. Aiptimise uses it to count AI crawler visits to your pages and keeps only a keyed hash of the IP address. A lost record never affects the page.
Every call to Aiptimise is signed with your site secret. The secret never leaves the Worker's secret variables.