A single index.html page that uses @rolloutctrl/js-sdk directly in the browser — no bundler, no build step. The SDK is loaded as an ES module from the esm.sh CDN.
The page evaluates the signup-button feature flag and renders the assigned variant's name directly as the call-to-action button label — whatever variant is configured in the dashboard (Sign Up, Free Trial 14 Days, Free Trial 30 Days, …) shows up on the button unchanged. Toggle the flag (or change its variant) in the RolloutCtrl dashboard and the UI updates automatically on the next poll.
| File | Purpose |
|---|---|
index.html |
The page itself — imports the SDK and renders the demo UI. |
config.js |
Default SDK configuration (sdk key, API URL, environment, flag key, context). |
config.local.example.js |
Template for local overrides. Copy to config.local.js (gitignored). |
.gitignore |
Ignores config.local.js so secrets stay out of git. |
-
Open
config.js(or copyconfig.local.example.jstoconfig.local.js) and fill in your values:window.ROLLOUTCTRL_CONFIG = { sdkKey: 'rctrl-client-********', apiUrl: 'http://localhost:3000/api', environment: 'production', refreshInterval: 15000, flagKey: 'signup-button', context: { country: 'US' }, };
-
Serve the directory with any static file server. Because the page uses
<script type="module">, you cannot openindex.htmldirectly viafile://— a real HTTP server is required.# Pick any of these: npx serve . # or npx http-server -p 8080 . # or python3 -m http.server 8080
-
Open http://localhost:8080 in your browser.
- The SDK is imported from
https://esm.sh/@rolloutctrl/js-sdk@1.0.0as an ES module. - A
RolloutCtrlClientis created with the values fromconfig.js(overridden byconfig.local.jsif present). - On the
readyevent the page callsclient.evaluate(flagKey, context)andclient.getVariant(flagKey, context)and renders the matching button. - On the
updatedevent (fired when the polled configuration changes) the page re-renders, so dashboard changes appear without a reload. - The
Re-evaluatebutton re-runs the local evaluation immediately. - The
Flush metricsbutton pushes aggregated exposure metrics to the server. - On
beforeunloadthe client is closed (metrics flushed, polling stopped).
If you want to use a locally built SDK instead of the CDN (e.g. for offline testing or against unreleased changes), build the package and point the import at the resulting ESM file:
# From the repo root:
yarn workspace @rolloutctrl/js-sdk build
# Copy the bundle next to index.html:
cp packages/sdk/js-sdk/dist/index.mjs ./vendor/rolloutctrl-js-sdk.mjsThen replace the import in index.html:
<script type="module">
import { RolloutCtrlClient } from './vendor/rolloutctrl-js-sdk.mjs';
// ...
</script>- The SDK uses
fetchandlocalStorage, so a real HTTP origin is required —file://will not work. - Pin the CDN URL to a specific version (e.g.
@1.0.0) to avoid surprise upgrades. - Keep your
sdkKeyinconfig.local.js(gitignored) rather thanconfig.jswhen committing changes.