Skip to main content

Overview

In this guide you evaluate flags in a browser app with shipdit/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 to client. Client keys (shipd_sdk_client_…) are safe to embed in browser bundles.
Never ship a server SDK key (shipd_sdk_server_…) to a browser. See Keys.

Create the client

src/lib/shipd.ts
The browser client adds these behaviors to the 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
Later checks reuse that identity, so you can call shipd.isEnabled("new-checkout") with no arguments. See Identify users.

Re-render on changes

Flag values change when a new snapshot arrives or when identify() 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 use defaults 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 after readyTimeoutMs (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 to createClient. The client serves it immediately and ready() resolves at once.
src/lib/shipd.ts
The snapshot format is documented in the Edge API reference.

Next