On this page
  1. Building it
  2. The files
  3. Hosting it
  4. Memory
  5. Size
  6. The browser backend
  7. What CI checks

The web build

The web build is the same game compiled to WebAssembly with Emscripten: four static files that any web server can serve, and a browser plays. CI builds it on every push, opens it in a headless browser and checks that the canvas shows the game; on a tag it goes into the release as web-build.zip, and to itch.io as a game that plays in the page.

Building it#

Locally, the web build needs the Emscripten SDK, activated in the shell you build from so that EMSDK is set:

rmp web
python3 -m http.server 8000 --directory build/web

Then open http://localhost:8000/my_game.html. Serve it: opening the file straight from disk does not work, because the page fetches the other files. Without the SDK, rmp web stops at the start with FAIL: the web build needs the emsdk: activate it first (source emsdk_env.sh, or emsdk_env.ps1 on Windows), so that EMSDK is set.

rmp web is cmake --preset web and a build, with the output in build/web/. The web preset is a release build, the same one CI makes.

The files#

FileWhat it is
my_game.htmlThe page: the canvas the game draws on, and the code that loads the rest.
my_game.jsEmscripten's runtime and the glue between the browser and the game.
my_game.wasmThe game itself — your code, the framework and raylib — compiled to WebAssembly.
my_game.dataYour resources/ folder, packed for the browser and mounted at /resources/ before the game starts.

web-build.zip holds these four and a LICENSES.txt of its own: the notices of what the web build contains, which leaves out what only the desktop builds link — GLFW, RGFW, glad, the Windows shims. The names come from [project] name; keep the files together in one folder, since the page finds the others by name next to itself.

The .data file is whatever resources/ holds when you build, as it is: the loose files, and also resources.rres if you have run rmp pack — in which case everything is in it twice. rmp unpack before a web build keeps it to one copy. CI builds the web from the loose files.

Hosting it#

The files are static, so anything that serves files over HTTP hosts the game: a static site, a bucket, a folder on a server you already have. CI itself serves them with Python's http.server for its browser test. On itch.io the game plays in the page — itch.io covers the upload.

What the browser changes, and what the framework does about it:

The frame
The browser owns the loop: the game draws a frame each time the browser asks the page for one. [window] fps and vsync do nothing on the web, and the framework never calls SetTargetFPS() there.
Saves
rmp::save writes to a folder kept in the browser's IndexedDB, so a save survives a reload. The game starts only once that folder has been read back, so its first scene finds the saves already there. The database is named after [project] name, so games served from the same site keep their saves apart. Where the browser has no IndexedDB or refuses it — a private window, storage switched off — the game still runs, and its saves last as long as the tab.
Sound
Browsers keep a page silent until the player does something. A click or a touch unlocks the sound, and so does a key press: a game played from the keyboard from its title screen on is not silent until the first click. A gamepad button does not count as a gesture to the browser.

Memory#

A WebAssembly module gets its memory when it starts. [web] memory is how much, in megabytes:

raylib_multiplatform.toml
[web]
memory = 256
grow   = false

The default, 64, is enough for menus and a handful of textures; a game that loads a tile atlas and a few music tracks wants more. When it runs out, the tab dies with "Cannot enlarge memory arrays" rather than a raylib error. grow = true lets the memory grow instead of aborting, and costs a little speed on every access to the heap; a game that knows its ceiling is better off raising memory and leaving grow off.

Below 16 nothing loads, and above 4096 is more than 32-bit WebAssembly can address at all, so both are refused:

raylib_multiplatform.toml
[web]
memory = 8
  raylib_multiplatform.toml:2: memory = 8
                               ^^^^^^^^^^

  configure: error: [web] memory = 8 has to be a whole number of megabytes between 16 and 4096. Below 16 nothing loads; above 4096 is past what a 32-bit wasm module can address at all.

Size#

What the player downloads is mostly the .wasm and the .data. What decides each:

  • The code is compiled for size (-Oz), and unused functions are dropped when it is linked.
  • No ASYNCIFY. The framework hands the frame loop to the browser instead of running a loop of its own, which is what lets it build without Emscripten's ASYNCIFY: that rewrites every function that could be on the stack while the game waits, and the framework's own measurement of it was a quarter more .wasm.
  • raylib modules you do not use. [raylib] disabled_modules takes rmodels or raudio out of the build — the only two it accepts. On a desktop the linker has removed most of what you do not call already; the web and Android are where it shows.
  • Your assets make up the .data, as they are in resources/.
raylib_multiplatform.toml
[raylib]
disabled_modules = ["rmodels"]

UPX is refused for the web, and the reason is the framework's: it is .wasm, and the browser fetches it gzipped anyway.

The browser backend#

Emscripten compiles the game either way. [web] backend chooses what raylib talks to inside the browser:

  • "glfw", the default: raylib calls GLFW, which Emscripten provides in JavaScript. The path raylib has shipped on the web for years.
  • "emscripten": raylib calls the browser through Emscripten's own API, with no GLFW layer. One layer less; the keyboard mapping in raylib's code for it is still marked unfinished, which is why it is not the default.

Both are opened in a headless browser by the framework's own CI. RGFW, raylib's third web backend, needs ASYNCIFY, and is refused:

raylib_multiplatform.toml
[web]
backend = "rgfw"
  raylib_multiplatform.toml:2: backend = "rgfw"
                               ^^^^^^^^^^^^^^^^

  configure: error: [web] backend = 'rgfw' cannot work here.
                    RGFW's web backend calls emscripten_sleep, which needs -sASYNCIFY. This framework deliberately has no ASYNCIFY: it hands the frame loop to emscripten_set_main_loop instead, and the measurement behind that decision is +26 % .wasm and +18 % download. Turning it on for one backend would put that cost on the build.
                    It BUILDS without it and then dies in the browser with "Please compile your program with async support" — which is how this was found: the boot test in .github/workflows/web-backends.yml opened it in Chromium.
                    Use one of emscripten, glfw.

What CI checks#

On every push — the web is in the fast lane — CI builds the game in its pinned image, checks that the four files exist and are not empty, and then plays it: it serves the folder, opens the page in headless Chromium, waits for the game to boot and draw, and takes a screenshot of the canvas. The run fails when the game does not report a clean boot — the console has to say RAY_TEST_BOOT_OK assets_failed=0, so an asset that is missing, or one that does not decode, fails it — when a save written to IndexedDB does not read back, or when the share of the canvas that differs from its most common colour is outside the range a real frame has — a blank canvas fails, and so does one that is all noise. An error in the browser's console fails it too, unless it is one of the few messages a headless browser prints on every clean run, and so does a file the page could not fetch. When the frame is the wrong one, the screenshot is uploaded with the run as web-canvas-capture, because a picture of the wrong frame says more than a ratio in a log.

Chromium is the one Playwright pins, and Playwright is pinned by the framework's package-lock.json.