const { client, isLoading } = useClientAsyncInit(
YOUR_CLIENT_KEY,
{ userID: "u_123" }
);
if (isLoading) {
return <div>Loading...</div>;
}
// Continue with initialized client
```text
```js JavaScript Example
const client = new StatsigClient(YOUR_CLIENT_KEY, { userID: "u_123" });
await client.initializeAsync();
// Client is now initialized with latest values
```ruby
</CodeGroup>
### 2. Bootstrap Initialization
> Ensures both latest assignments with no rendering latency
Bootstrapping allows you to initialize the client with a JSON string. This approach ensures that values are immediately available without the client making any network requests. Note that you will be responsible for keeping these values up to date.
With this approach, your server will be responsible for serving the configuration payload to your client app on page load (for web implementations) or during app launch (for mobile implementations).
<CodeGroup>
```tsx React Bootstrap
// Server-generated initialization values
const initValues = getStatsigValuesFromServer(user);
const { client } = useClientAsyncInit(
YOUR_CLIENT_KEY,
{ userID: "u_123" },
{ initializeValues: initValues }
);
// Client renders immediately with server values
```text
```js JavaScript Bootstrap
const bootstrapValues = getInitializationValuesFromServer();
const client = new StatsigClient(
YOUR_CLIENT_KEY,
{ userID: "u_123" },
{ initializeValues: bootstrapValues }
);
```python
</CodeGroup>
### 3. Asynchronous Initialization - Not Awaited
If you want to fetch the latest values without awaiting the asynchronous call, you can call `initializeAsync` and catch the promise.
This approach provides immediate rendering with cached values initially, which will update to the latest values mid-session.
<Warning>
Be aware that the values may switch when checked a second time after the latest values have been loaded.
</Warning>
### 4. Synchronous Initialization
> Ensures immediate rendering but uses cached assignments (when available)
When calling `StatsigClient.initializeSync`, the client uses cached values if they are available. The client fetches new values in the background and updates the cache. This approach provides immediate rendering, but the values might be stale or absent during the first session.
These strategies help you balance the need for the latest gate / experiment assignment information with the need for immediate application rendering based on your specific requirements.
</Tab>
<Tab title="Server SDKs">
## General Initialization Flow
Server SDKs require only a secret key to initialize. As most servers are expected to deal with many users - server SDKs download all rules and configurations you have in your project and evaluate them in realtime for each user that is encountered. The process for Server SDK initialization looks something like this:
1. Your server checks if you have locally cached values (which you can set up with a [DataAdapter](/server/concepts/data_store/))
2. If your server found values on the last call, it'll be ready for checks with the reason "DataAdapter". Whether it found local data or not, it'll next go to the network to find updated values.
3. The Server retrieves updated rules from the server, and is now ready for checks even if it didn't find values in step 1.
4. Going forward, the server will retrieve new values every 10 seconds from the server, updating the locally cached values each time.
DataAdapters provide a layer of resilience, and ensure your server is ready to server requests as soon as it startups rather than waiting for a network roundtrip, which can be especially valuable if you have short-lived or serverless instances. While only recommended for advanced setups, Statsig also offers a [Forward Proxy](/server/concepts/forward_proxy/) that can add an extra layer of resilience to your server setup.
<CodeGroup>
```js Node.js Initialization
import { Statsig, StatsigUser } from '@statsig/statsig-node-core';
const statsig = new Statsig("YOUR_SERVER_KEY");
await statsig.initialize();
// Server SDK is now ready to evaluate gates/experiments for any user
const user = new StatsigUser({ userID: "123" });
const gate = statsig.checkGate(user, "my_gate");
```text
```python Python Initialization
from statsig_python_core import Statsig, StatsigUser
statsig = Statsig("YOUR_SERVER_KEY")
statsig.initialize().wait()
# Server SDK is now ready
user = StatsigUser("123")
gate = statsig.check_gate(user, "my_gate")