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 guideRecipesAPI ReferenceChangelog
Dev guideAPI ReferenceRecipesChangelogUser GuideGitHubDev CommunityOptimizely AcademySubmit a ticketLog In
Dev guide

Cloudflare Workers

Describes the JavaScript template hosted on GitHub for running Optimizely Feature Experimentation feature flags and experiments on Cloudflare Workers

Cloudflare Workers provide a serverless execution environment for creating or augmenting existing applications without infrastructure maintenance. The Feature Experimentation 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.

📘

Note

Although Cloudflare lets you write code in various programming languages, Optimizely provides a template for JavaScript. only.

Use cases

See Cloudflare Examples documentation.

Restrictions and limitations

Cloudflare Workers have different plan limits and restrictions based on your account. See the official Cloudflare Limits documentation.

Optimizely + Cloudflare Worker template

The Feature Experimentation Cloudflare Workers template embeds and extends the Feature Experimentation JavaScript SDK 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 documentation.

📘

Note

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 to provide performant caching for the Feature Experimentation datafile. See Caching with Cloudflare section in the readme on GitHub for information.

Identity management

Optimizely's Feature Experimentation SDKs require passing a user-provided identifier at runtime 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. 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.

Bucketing

See How bucketing works.

How to use

Prerequisites

Get started

See the GitHub readme file for implementation details.

Additional resources