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.
NoteAlthough 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.
NoteThis 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
- You must install the Wrangler CLI for this template.
Get started
See the GitHub readme file for implementation details.
Additional resources
Updated about 5 hours ago