Date of slack thread: 5/7/24
Anonymous: Hi Team, we are using statsig node SDK on sever of our next js app, once the SDK is initialised we send the intialisation data via getServerSideProps to the client. On client side we are using this data to initialise the StatsigSynchronousProvider.
Everything seems to be working as expected, I just have one concern, since the rendering is completely blocked on sever while I execute Statsig.initialise(), is there any way to add a custom cutoff time to reduce the delay in main page load? Or is there any inbuilt cutoff?
Statbot: When using the Statsig Node SDK on the server side of a Next.js application, it’s important to manage the initialization time to ensure that it doesn’t excessively delay the rendering of your main page. The documentation does not explicitly mention a built-in cutoff time or a way to set a custom cutoff time for the Statsig.initialize()
method. However, to mitigate potential delays, you can initialize the Statsig SDK synchronously. This approach requires a client SDK and a server SDK, and it is considered the most performant way to integrate Statsig into your website. By using a server SDK to generate the gate and experiment values for the given user, you can initialize the Statsig SDK synchronously on the client side without waiting for a network round trip to Statsig servers (source). If you’re already using StatsigSynchronousProvider
on the client side with the initialization values generated by the server SDK, you are following the recommended approach for server-side rendering (SSR) to avoid delays and flicker effects (source). If you are experiencing significant delays and the documentation does not provide a solution, it may be worth exploring optimization strategies within your application’s architecture or considering asynchronous initialization patterns that do not block rendering. If the delay remains a concern, it’s advisable to profile your server-side code to identify the bottleneck and optimize accordingly.
Cooper Reid (Statsig): The initTimeoutMs initialization option will allow you to set the max time Statsig should try to initialize. After that time has elapses, the client will call back to default values defined in code for the parameter getter methods.
Cooper Reid (Statsig): You should only be calling initialize once when the web server starts, not for every incoming network request to your server. You can see here in this example that initializes called once and all subsequent calls to the SDK are evaluated locally and have a minimal amount of latency.
Anonymous: Thanks!
Statbot: This thread has been marked as resolved. Press below to re-open.