Optimizely Full Stack

A basic starter kit for Fastly's Compute@Edge with Optimizely built in.

Warning: The code provided on this page is not written or maintained by Fastly. We don't provide direct support for third party services or code. See our Terms of Service for more information.

Use this starter

Using the Fastly CLI, create a new project using this starter somewhere on your computer:

$ fastly compute init --from=https://github.com/optimizely/fastly-compute-starter-kit

Or click the button below to create a GitHub repository, provision a Fastly service, and set up continuous deployment:

Deploy to Fastly

External Calls via Fastly Backends

This starter kit overrides the standard Optimizely Javascript SDK's external calls to use Compute@Edge's fetch against registered backend endpoints. This backend setup also provides performant caching for the Optimizely Datafile.

Identity Management

Out of the box, Optimizely's Full Stack SDKs require a user-provided identifier to be passed in 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.


For more information on how Optimizely Full Stack SDKs assign users to feature flags and experiments, see the documentation on how bucketing works.

How to use


You will need to complete the following prerequisites to use this template:

  • Have a Compute@Edge account and the Fastly CLI installed. For more information view the Compute@Edge getting started documentation.
  • Have an Optimizely account. If you do not have an account, you can register for a free account.

Get started

  1. Create a new folder and initialize a Fastly Compute@Edge service using the Fastly CLI from this template.

    fastly compute init --from https://github.com/optimizely/fastly-compute-starter-kit
  2. Follow the wizard and provide the service name, description and any other information. a) Add your service_id to fastly.toml, if you want to use an existing Fastly service.

  3. Update your Optimizely sdkKey and flagKey in src/index.js. Your SDK keys can be found in the Optimizely application under Settings.

  4. Build and publish:

    fastly compute publish
  5. Monitor logs:

    fastly log-tail

Additional resources

Next steps

Starters are a good way to bootstrap a project. For more specific use cases, and answers to common problems, try our library of code examples.