Skip to content

Commit 9fd6c00

Browse files
committed
docs: move bootstrapFlags to below remoteConfig
1 parent 1ca0e7f commit 9fd6c00

1 file changed

Lines changed: 62 additions & 62 deletions

File tree

packages/browser-sdk/README.md

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -113,68 +113,6 @@ type Configuration = {
113113
};
114114
```
115115

116-
## Server-side rendering and bootstrapping
117-
118-
For server-side rendered applications, you can eliminate the initial network request by bootstrapping the client with pre-fetched flag data.
119-
120-
### Init options bootstrapped
121-
122-
```typescript
123-
type Configuration = {
124-
logger: console; // by default only logs warn/error, by passing `console` you'll log everything
125-
apiBaseUrl?: "https://front.reflag.com";
126-
sseBaseUrl?: "https://livemessaging.bucket.co";
127-
feedback?: undefined; // See FEEDBACK.md
128-
enableTracking?: true; // set to `false` to stop sending track events and user/company updates to Reflag servers. Useful when you're impersonating a user
129-
offline?: boolean; // Use the SDK in offline mode. Offline mode is useful during testing and local development
130-
bootstrappedFlags?: FetchedFlags; // Pre-fetched flags from server-side (see Server-side rendering section)
131-
};
132-
```
133-
134-
### Using bootstrappedFlags
135-
136-
Use the Node SDK's `getFlagsForBootstrap()` method to pre-fetch flags server-side, then pass them to the browser client:
137-
138-
```typescript
139-
// Server-side: Get flags using Node SDK
140-
import { ReflagClient as ReflagNodeClient } from "@reflag/node-sdk";
141-
142-
const serverClient = new ReflagNodeClient({ secretKey: "your-secret-key" });
143-
await serverClient.initialize();
144-
145-
const { flags } = serverClient.getFlagsForBootstrap({
146-
user: { id: "user123" },
147-
company: { id: "company456" },
148-
});
149-
150-
// Pass flags data to client using your framework's preferred method
151-
// or for example in a script tag
152-
app.get("/", (req, res) => {
153-
res.set("Content-Type", "text/html");
154-
res.send(
155-
Buffer.from(
156-
`<script>var flags = ${JSON.stringify(flags)};</script>
157-
<main id="app"></main>`,
158-
),
159-
);
160-
});
161-
162-
// Client-side: Initialize with pre-fetched flags
163-
import { ReflagClient } from "@reflag/browser-sdk";
164-
165-
const reflagClient = new ReflagClient({
166-
publishableKey: "your-publishable-key",
167-
user: { id: "user123" },
168-
company: { id: "company456" },
169-
bootstrappedFlags: flags, // No network request needed
170-
});
171-
172-
await reflagClient.initialize(); // Initializes all but flags
173-
const { isEnabled } = reflagClient.getFlag("huddle");
174-
```
175-
176-
This eliminates loading states and improves performance by avoiding the initial flags API call.
177-
178116
## Migrating from Bucket SDK
179117

180118
If you have been using the Bucket SDKs, the following list will help you migrate to Reflag SDK:
@@ -289,6 +227,66 @@ const flags = reflagClient.getFlags();
289227
Just as `isEnabled`, accessing `config` on the object returned by `getFlags` does not automatically
290228
generate a `check` event, contrary to the `config` property on the object returned by `getFlag`.
291229

230+
## Server-side rendering and bootstrapping
231+
232+
For server-side rendered applications, you can eliminate the initial network request by bootstrapping the client with pre-fetched flag data.
233+
234+
### Init options bootstrapped
235+
236+
```typescript
237+
type Configuration = {
238+
logger: console; // by default only logs warn/error, by passing `console` you'll log everything
239+
apiBaseUrl?: "https://front.reflag.com";
240+
sseBaseUrl?: "https://livemessaging.bucket.co";
241+
feedback?: undefined; // See FEEDBACK.md
242+
enableTracking?: true; // set to `false` to stop sending track events and user/company updates to Reflag servers. Useful when you're impersonating a user
243+
offline?: boolean; // Use the SDK in offline mode. Offline mode is useful during testing and local development
244+
bootstrappedFlags?: FetchedFlags; // Pre-fetched flags from server-side (see Server-side rendering section)
245+
};
246+
```
247+
248+
### Using bootstrappedFlags
249+
250+
Use the Node SDK's `getFlagsForBootstrap()` method to pre-fetch flags server-side, then pass them to the browser client:
251+
252+
```typescript
253+
// Server-side: Get flags using Node SDK
254+
import { ReflagClient as ReflagNodeClient } from "@reflag/node-sdk";
255+
256+
const serverClient = new ReflagNodeClient({ secretKey: "your-secret-key" });
257+
await serverClient.initialize();
258+
259+
const { flags } = serverClient.getFlagsForBootstrap({
260+
user: { id: "user123" },
261+
company: { id: "company456" },
262+
});
263+
264+
// Pass flags data to client using your framework's preferred method
265+
// or for example in a script tag
266+
app.get("/", (req, res) => {
267+
res.set("Content-Type", "text/html");
268+
res.send(
269+
Buffer.from(
270+
`<script>var flags = ${JSON.stringify(flags)};</script>
271+
<main id="app"></main>`,
272+
),
273+
);
274+
});
275+
276+
// Client-side: Initialize with pre-fetched flags
277+
import { ReflagClient } from "@reflag/browser-sdk";
278+
279+
const reflagClient = new ReflagClient({
280+
publishableKey: "your-publishable-key",
281+
user: { id: "user123" },
282+
company: { id: "company456" },
283+
bootstrappedFlags: flags, // No network request needed
284+
});
285+
286+
await reflagClient.initialize(); // Initializes all but flags
287+
const { isEnabled } = reflagClient.getFlag("huddle");
288+
```
289+
292290
## Updating user/company/other context
293291

294292
Attributes given for the user/company/other context in the ReflagClient constructor can be updated for use in flag targeting evaluation with the `updateUser()`, `updateCompany()` and `updateOtherContext()` methods.
@@ -306,6 +304,8 @@ await reflagClient.updateUser({ voiceHuddleOptIn: (!isEnabled).toString() });
306304

307305
> [!NOTE] > `user`/`company` attributes are also stored remotely on the Reflag servers and will automatically be used to evaluate flag targeting if the page is refreshed.
308306
307+
This eliminates loading states and improves performance by avoiding the initial flags API call.
308+
309309
## Toolbar
310310

311311
The Reflag Toolbar is great for toggling flags on/off for yourself to ensure that everything works both when a flag is on and when it's off.

0 commit comments

Comments
 (0)