Readme · Guides · Reference · Contributing
The Optimization SDK Suite is pre-release (alpha). Breaking changes can be published at any time.
This is a reference implementation for the Optimization Web SDK and is part of the Contentful Optimization SDK Suite.
Use this implementation when you need the smallest browser example for the Web SDK without a framework layer. It demonstrates a static HTML integration, Web Components entry rendering, local mock API usage, Web SDK asset copying, and Playwright coverage for browser-side optimization, tracking, live updates, consent gating, and offline recovery behavior.
The static app uses en-US as its application locale for both the Web SDK top-level locale and
Contentful CDA getEntry() calls. Do not use withAllLocales or locale=*; SDK entry resolution
expects direct single-locale fields such as fields.nt_experiences and fields.nt_variants. See
Locale handling in the Optimization SDK Suite
for the broader locale model and
Entry personalization and variant resolution
for the entry contract.
.nvmrc)Run all steps from the monorepo root.
Install pnpm packages:
pnpm install
Build the local package tarballs consumed by implementations:
pnpm build:pkgs
Install this implementation so its local @contentful/* dependencies resolve from pkgs/:
pnpm implementation:run -- web-sdk implementation:install
Create the local .env file if it does not already exist:
test -f implementations/web-sdk/.env || cp implementations/web-sdk/.env.example implementations/web-sdk/.env
The .env.example values are valid only against the mock server implementation. To test the
implementation against a live server environment, see the
mocks package for information on how to set up Contentful space with
test data.
Run these commands from the monorepo root.
Start servers:
pnpm implementation:run -- web-sdk serve
Stop servers:
pnpm implementation:run -- web-sdk serve:stop
Run E2E:
pnpm test:e2e:web-sdk
The application can be accessed via Web browser at http://localhost:3000. See
implementations/web-sdk/package.json for lower-level local commands. The local server is a
lightweight Node.js HTTP server that reads .env or .env.example, injects those values into the
HTML, and serves public/; PM2 manages the serve and serve:stop processes.
E2E tests are run using Playwright.
Install implementation dependencies:
pnpm setup:e2e:web-sdk
Install the shared Playwright browser binaries and system dependencies used by lib/e2e-web:
pnpm --dir lib/e2e-web setup:e2e
Run the E2E test suite:
pnpm test:e2e:web-sdk
The tests can alternatively be run using Playwright's GUI:
pnpm implementation:run -- web-sdk test:e2e:ui