Installation

The Loby JavaScript SDK is loaded via a script tag from our CDN. No npm package or build step is required.

Adding the SDK

Add the following code to your HTML, typically before the closing </body> tag:

Copy
<script> window.lobyAsyncInit = async function() { await Loby.init({ clientId: 1234, version: 'v1' }) }; </script> <script async defer crossorigin="anonymous" src="https://js.loby.io/sdk.js"></script>

Understanding the Loading Pattern

The SDK uses an async initialization pattern:

  1. Define lobyAsyncInit - This function is called automatically when the SDK has loaded
  2. Load the script - The script is loaded asynchronously to avoid blocking page rendering
  3. SDK calls lobyAsyncInit - Once loaded, the SDK invokes your initialization function

This pattern ensures the SDK is fully loaded before you attempt to use it.

Script Attributes

AttributePurpose
asyncLoads the script asynchronously without blocking HTML parsing
deferExecutes the script after the document has been parsed
crossorigin="anonymous"Enables CORS for the script request

Waiting for SDK Ready

If you need to ensure the SDK is loaded before executing code elsewhere on your page, you can set a flag:

Copy
<script> window.lobyAsyncInit = async function() { await Loby.init({ clientId: 1234, version: 'v1' }) window.lobySDKLoaded = true }; </script> <script async defer crossorigin="anonymous" src="https://js.loby.io/sdk.js"></script>

Then in your application code:

Copy
async function waitForLoby() { while (!window.lobySDKLoaded) { await new Promise(resolve => setTimeout(resolve, 50)) } // SDK is ready }
Previous
Overview
Next
Initialization