Skip to content

Commit 7e7d81f

Browse files
brock-statsigBrock Lumbard
and
Brock Lumbard
authored
ssg guide (#3073)
Co-authored-by: Brock Lumbard <[email protected]>
1 parent 79a6f36 commit 7e7d81f

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

docs/client/javascript-mono/nextjs/NextJsUsage.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import * as LogEvent from "./_nextJsLogEvent.mdx";
4040
import * as SrAndAc from "../_sessionReplayAutoCapture.mdx";
4141
import * as Advanced from "./_nextJsAdvanced.mdx";
4242
import * as FlagsSDK from "./_nextJsFlagsSdk.mdx";
43+
import * as SSG from "./_nextJsSSG.mdx"
4344

4445
export const Builder = SDKDocsBuilder({
4546
sections: [
@@ -61,6 +62,7 @@ export const Builder = SDKDocsBuilder({
6162
[Advanced, {}],
6263
[Bootstrap, {}],
6364
[Proxy, {}],
65+
[SSG, {}],
6466
[FlagsSDK, {}],
6567
]
6668
})
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## Statsig Site Generation (SSG)
2+
3+
Vercel's [Static Site Generation](https://vercel.com/blog/nextjs-server-side-rendering-vs-static-generation) renders the HTML for your site at build time (rather than request time), optimizing the performance of HTML delivery. Static pre-rendered content can't be responsive, so its difficult to run experiments on, or flag your features. We recommend two approaches to experimenting on Static-Generated Content:
4+
- **1. Use Vercel's Edge Middleware:** With the Edge Middleware and tools like [Statsig's Edge Config Adapter](https://docs.statsig.com/integrations/vercel/#using-the-statsig-sdk), you can experiment on the entirety of your static generated content with zero-latency redirect tests.
5+
- **2. Isolate Statsig Usage to Hydrated Elements:** Often SSG'd pages are "hydrated" with addition client-rendered content that is more responsive and dynamic. Statsig usage can be isolated to these elements, supporting SSG's first-render speeds, and loading in experimented content after the fact.
6+
7+
Typically, approach #2 is executed by installing the \<StatsigProvider> only around content that will be client-side rendered. In some cases, you might have multiple client-rendered components without a common parent - in those cases you'll need multiple StatsigProviders, while having them share a single client instance. Do this by initializing a StatsigClient using the regular javascript syntax:
8+
9+
```jsx
10+
const myStatsigClient = new StatsigClient(YOUR_SDK_KEY, user, options);
11+
await myStatsigClient.initializeAsync();
12+
```
13+
14+
And then plug this client object into the providers as needed, managing the client object as a singleton if needed.
15+
16+
```jsx
17+
<StatsigProvider client={myStatsigClient}>
18+
<YourComponent />
19+
</StatsigProvider>
20+
21+
<StatsigProvider client={myStatsigClient}>
22+
<YourComponent />
23+
</StatsigProvider>
24+
```
25+
26+

0 commit comments

Comments
 (0)