Skip to main content

HTML5 / JavaScript

The HTML5 SDK is the canonical integration. It's a single <script> tag that exposes window.Funox.SDK.

Install

Add this to your <head> (or just before your game's bundle):

HTML1 line
1<script src="https://sdk.funox.com/funox-sdk-v1.js"></script>

Initialize

JavaScript1 line
1await window.Funox.SDK.init();

Or with promises:

JavaScript6 lines
1window.Funox.SDK.init()2  .then(() => bootGame())3  .catch((err) => {4    console.warn("Funox SDK init failed", err);5    bootGame(); // boot anyway — SDK degrades gracefully6  });

Minimal integration

JavaScript19 lines
1async function main() {2  await window.Funox.SDK.init();3 4  window.Funox.SDK.game.loadingStart();5  await loadAssets();6  window.Funox.SDK.game.loadingStop();7 8  startMainMenu();9}10 11function startGameplay() {12  window.Funox.SDK.game.gameplayStart();13}14 15function stopGameplay() {16  window.Funox.SDK.game.gameplayStop();17}18 19main();

Sitelock

Prevent your game from running on domains you don't control. Add this before loading game logic:

JavaScript13 lines
1const allowed = [2  "funox.com",3  "www.funox.com",4  "embed.funox.com",5  "localhost",6  "127.0.0.1",7];8 9const host = window.location.hostname;10if (!allowed.some((d) => host === d || host.endsWith("." + d))) {11  document.body.innerHTML = "<h1>This game is hosted on funox.com</h1>";12  throw new Error("sitelock");13}

Common patterns

Pause heavy work when the tab is hidden

JavaScript9 lines
1document.addEventListener("visibilitychange", () => {2  if (document.hidden) {3    game.pause();4    window.Funox.SDK.game.gameplayStop();5  } else {6    game.resume();7    window.Funox.SDK.game.gameplayStart();8  }9});

Handle incognito-mode localStorage safely

JavaScript9 lines
1function safeGet(key) {2  try { return localStorage.getItem(key); }3  catch { return null; }4}5 6function safeSet(key, value) {7  try { localStorage.setItem(key, value); }8  catch { /* incognito: ignore */ }9}

Build tips

  • Bundle all assets — no external CDNs.
  • Ship WebP/AVIF where possible.
  • Use code splitting to keep the initial bundle ≤ 50 MB.
  • Compress assets with Brotli on your CDN.

Where to go next