---
title: Cloudflare Workers
slug: feature-experimentation/docs/cloudflare-workers
createdAt: 2026-08-05T20:39:57.000Z
---

[Cloudflare Workers](https://workers.cloudflare.com/) provide a serverless execution environment for creating or augmenting existing applications without infrastructure maintenance. The [Feature Experimentation Cloudflare Worker template](https://github.com/optimizely/cloudflare-worker-template) helps you get started with Feature Experimentation using Cloudflare Workers.

## Cloudflare Workers

### Key advantages

- **Automatic scaling** – Traffic is automatically routed and load balanced across servers.
- **High-performance global network** – Your code is powered by Cloudflare's global network.
- **Multiple languages** – You can write in JavaScript, Rust, C, and C++.
- **No cold starts** – Cloudflare supports 0 MS cold starts.

:::hint{type="info"}
Although Cloudflare lets you write code in [various programming languages](https://developers.cloudflare.com/workers/platform/languages/), Optimizely provides a template for JavaScript only.
:::

### Use cases

See [Cloudflare Examples documentation](https://developers.cloudflare.com/workers/examples/).

### Restrictions and limitations

Cloudflare Workers have different plan limits and restrictions based on your account. See the official Cloudflare [Limits documentation](https://developers.cloudflare.com/workers/platform/limits/).

## Optimizely + Cloudflare Worker template

The Feature Experimentation Cloudflare Workers template embeds and extends the [Feature Experimentation JavaScript SDK](docId\:Xg7P2ux5Cd5t461rYTc6o) to provide a starting point for you to implement experimentation and feature flagging for your experiences at the edge. For a general guide to getting started with Feature Experimentation, see the [JavaScript SDK quickstart](docId\:FcM5PaCjwrFb_kRI0qpua) documentation.

:::hint{type="info"}
This starter kit makes use of the "Universal" version of the Feature Experimentation JavaScript SDK which explicitly excludes the datafile manager and event processor features for better performance.

The datafile is fetched and cached using Cloudflare's cache API, and event dispatching is handled through the provided platform-specific `getOptimizelyClient()` helper.
:::

### Cache with Cloudflare

This template uses the [Cloudflare Cache API](https://developers.cloudflare.com/workers/runtime-apis/cache/) to provide performant caching for the Feature Experimentation [datafile](docId\:LZrelZVwEZgiXEYUaEQi6). See [Caching with Cloudflare section in the readme on GitHub](https://github.com/optimizely/cloudflare-worker-template?tab=readme-ov-file#caching-with-cloudflare) for information.

### Identity management

Optimizely's Feature Experimentation SDKs require [passing a user-provided identifier at runtime ](docId\:j0PPoMJWYbz04K76EKLUI) to drive experiment and feature flag decisions. This example generates a unique ID, stores it in a cookie, and reuses it to make the [decisions sticky](docId\:g0ydY7XzuuT9yqJzZgZuG). Alternatively, you can use an existing unique identifier available within your application and pass it in as the value for the `OPTIMIZELY_USER_ID` cookie.

### How bucketing works

See [How bucketing works](docId\:d31cP4wLKZws83yx-R50O).

## How to use

### Prerequisites

- You must install the [Wrangler CLI](https://developers.cloudflare.com/workers/cli-wrangler) for this template.

### Get started

See the [GitHub readme file](https://github.com/optimizely/cloudflare-worker-template/blob/master/README.md) for implementation details.

## Additional resources

- [Cloudflare Workers](https://workers.cloudflare.com/).
- [Cloudflare Workers documentation](https://developers.cloudflare.com/workers/).
- [Cloudflare Workers tutorials](https://developers.cloudflare.com/workers/tutorials).
- [Cloudflare Workers with Optimizely Template on GitHub](https://github.com/optimizely/cloudflare-worker-template).
