Overview
In this guide you evaluate flags in a browser app withshipdit/client. It has the same evaluation API as the server client, plus a localStorage snapshot cache, a stable anonymous id, and automatic location traits. Using React? Read React after this page.
Install
Use a client SDK key
In the dashboard, go to SDK keys, click Create SDK key, and set Key type toclient. Client keys (shipd_sdk_client_…) are safe to embed in browser bundles.
Create the client
src/lib/shipd.ts
createClient options:
Location traits come from edge geolocation and the browser’s time zone. Traits you pass yourself win. See Target users.
Identify on login, reset on logout
src/auth.ts
shipd.isEnabled("new-checkout") with no arguments. See Identify users.
Re-render on changes
Flag values change when a new snapshot arrives or whenidentify() or reset() runs. subscribe() calls your listener on each change and returns an unsubscribe function.
src/main.ts
Avoid a flash of default content
The first render may usedefaults while the snapshot loads. Pick one approach:
- Wait for
ready()before rendering flag-dependent UI. It resolves when the snapshot or cached snapshot loads, or afterreadyTimeoutMs(5 seconds by default). - Rely on the persisted cache. Returning visitors start from the snapshot saved in
localStorage. - Pass
bootstrap. If your server already has a snapshot for the same environment, embed it in the page and pass it tocreateClient. The client serves it immediately andready()resolves at once.
src/lib/shipd.ts