Skip to content

Web games

Scope: games that run in a web browser, whether they're written for the web with a JavaScript framework such as Phaser 4, three.js, Babylon.js or PixiJS 8, or exported from an engine: Unity 6 Web builds (Unity 6.3 LTS to 6.6), Godot 4 web exports (4.7 is current), and GameMaker's HTML5 and GX.games targets. The rules cover engine exports and hosting, download size, the game loop in a browser tab, audio and input, saves in browser storage, publishing on itch.io and web game portals, and performance. WebGL and WebGPU rendering, including the WebGL 2 fallback (GFX-15) and lost contexts (GFX-16), are in Graphics and GPU rendering; the fixed time step (GAMEDEV-1), save versioning (GAMEDEV-10 and GAMEDEV-11) and frame budgets (GAMEDEV-12) are in Game development; and accessibility, security headers and HTTP caching for any web page are in Web front end. Engine rules are in Unity, Godot and GameMaker, store rules for phones in Mobile games, multiplayer servers and backends in Game servers and online services, and hosting on Vercel, Netlify and Cloudflare in Serverless and edge hosting.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

No single guide covers web games. Use the guide for your engine or framework, and the requirements of each site you publish on, as the baselines.

  • 8 Web (Unity Manual): the baseline for Unity Web builds: browser support, WebGL 2 and WebGPU, memory, multithreading, compression and server configuration, caching, and optimising for size and for mobile browsers.
  • 8 Exporting for the Web (Godot docs): the baseline for Godot web exports: WebGL 2 and the Compatibility renderer, thread support, progressive web apps, the platform's limits, and serving the files.
  • 7 Game development (MDN): browser game techniques, from the anatomy of a main loop to the web APIs games use, control mechanisms and publishing.
  • 7 Phaser concepts: Scenes, Loader and Textures (Phaser docs): the scene life cycle, where to load assets, and sprite sheets and texture atlases.
  • 7 three.js manual (three.js): fundamentals, responsive canvases, disposing of objects, and optimising scenes with many objects.
  • 7 Optimizing Your Scene (Babylon.js docs): instances, frozen materials and meshes, culling and the scene optimiser.
  • 7 Uploading HTML5 games and the butler manual (itch.io): ZIP requirements, embed options and precompressed files, and pushing builds with butler push, from CI with a BUTLER_API_KEY secret.
  • 7 Requirements (Poki) and Technical requirements (CrazyGames): what each portal checks before it publishes a game: file size, devices and browsers, input, SDK integration and ads.
  • 7 Storage for the web (web.dev): which browser storage API to use, how much you can store, and how eviction works.
  • 6 Setting Up For GX Games and HTML5: Common Issues and Differences To VM/YYC (GameMaker Help Centre): GameMaker's two web targets and how they differ from the desktop targets.
  • 6 Performance Tips (PixiJS): sprite sheets and batching, culling, textures, text, filters and blend modes.

Key rules

Engine exports and hosting

  • 8 WEBGAME-1 Before you choose a scripting language, renderer or plugins, check what the engine's web export supports. Godot 4 can't export C# projects to the web and runs there only with the Compatibility renderer on WebGL 2 (GODOT-16 and GODOT-21). Unity uses WebGL 2 by default, and WebGPU has limited browser and device support, so if you add WebGPU, keep WebGL 2 after it in the Graphics API list as the fallback (GFX-15). In GameMaker, the GX.games target behaves more like the desktop targets than the HTML5 target does, and if you use HTML5, keep WebGL on. (Godot, Exporting for the Web, Godot, WebGL version, Unity, Compare WebGPU and WebGL2, Unity, Enable the WebGPU graphics API, GameMaker, Setting Up For GX Games, GameMaker, HTML5: Common Issues and Differences To VM/YYC)
  • 7 WEBGAME-2 Serve the engine's precompressed build files over HTTPS with the matching Content-Encoding header, gzip for .gz and br for .br files, and serve .wasm files as application/wasm. Unity's decompression fallback works without the header, but makes the loader larger and loading less efficient, and Chrome and Firefox decompress Brotli natively only over HTTPS. Godot recommends compressing the large .pck and .wasm files on the server, and itch.io sets the header from the .gz or .br extension. With another MIME type, WebAssembly.instantiateStreaming() fails and the browser can't compile the module while it downloads. (Unity, Deploy a Web application, Godot, Serving the files, itch.io, Compression, MDN, WebAssembly.instantiateStreaming())
  • 7 WEBGAME-3 Export without threads unless you control the headers of every page that hosts the game. Threads in WebAssembly builds need SharedArrayBuffer, which needs a secure context and cross-origin isolation: Cross-Origin-Opener-Policy: same-origin and Cross-Origin-Embedder-Policy: require-corp on the page, allow="cross-origin-isolated" on every iframe in the chain, and an opt-in from every cross-origin resource, which rules out most ads and third-party scripts. Godot exports single-threaded by default since 4.3, and its docs call that more compatible with itch.io, Poki and CrazyGames; Unity's Enable Native C/C++ Multithreading needs the same headers. (Godot, Exporting for the Web, Godot, Thread and extension support, Unity, Introduction to Web multithreading, MDN, SharedArrayBuffer: security requirements, web.dev, Isolation in iframes)
  • 6 WEBGAME-4 Ship GPU texture formats for both desktop and mobile browsers: in Unity, make two builds, one with DXT for desktop and one with ASTC for mobile browsers, and in Godot, turn on VRAM texture compression for both desktop and mobile in the web export preset. In Unity, a device that doesn't support the build's format decompresses the textures in software, which uses more memory and can run slower; in Godot, enabling both makes the export bigger but more compatible. This applies GFX-13. (Unity, Texture compression in Web, Godot, Export options)

Loading

Game loop and page lifecycle

  • 7 WEBGAME-7 When the page becomes hidden, pause the game, suspend the AudioContext and save progress. Listen for visibilitychange: the hidden state is often the last change a page can observe, especially on mobile, where closing the tab or the browser fires no pagehide or unload. Browsers stop requestAnimationFrame in hidden tabs, which stops engine loops such as Godot's _process() and can disconnect networked games, but they don't throttle tabs that play audio. Phaser pauses its game when the page is hidden and emits hidden and visible events. (MDN, Page Visibility API: policies for background pages, Chrome for Developers, Page Lifecycle API: hidden, MDN, AudioContext.suspend(), Godot, Background processing, Phaser, Game: events)
  • 6 WEBGAME-8 If you write your own game loop, drive it with requestAnimationFrame, request the next frame before doing the frame's work, and advance the fixed time step of GAMEDEV-1 from the callback's timestamp. Don't update on setInterval or setTimeout, which keep using the CPU when the game is minimized and compete with rendering for the main thread. requestAnimationFrame follows the display's refresh rate, commonly 60 Hz but also 120 or 144 Hz, and pauses in background tabs, so keep GAMEDEV-1's cap on steps per frame. (MDN, Anatomy of a video game, MDN, requestAnimationFrame())

Audio and input

  • 7 WEBGAME-9 Start audio from the player's first click, tap or key press, for example on a "tap to play" screen, and resume the AudioContext from a later tap whenever it is suspended or interrupted. Browsers block audio until the player has interacted with the page, and an AudioContext created before that starts suspended. On iOS, the context is interrupted when the game goes to the background or a call comes in, and only a new user gesture can resume it, not a visibilitychange handler. Unity and Godot both suggest a loading or splash screen that asks for this first interaction. (MDN, Web Audio API best practices: autoplay policy, MDN, Autoplay guide: availability, MDN, BaseAudioContext.state, CrazyGames, Resuming audio after iOS interrupts it, Unity, Audio in Web, Godot, Audio)
  • 7 WEBGAME-10 Handle mouse, touch and pen with Pointer Events on the game canvas, set touch-action: none on the canvas only, and if the game runs in mobile browsers, give it touch controls and a layout for each orientation it supports. touch-action: none stops the browser from panning and zooming the game surface, and on the whole page it would also stop players with low vision from zooming. CrazyGames requires mouse, keyboard and touch for games that support mobile, and Poki requires mobile games to fill the screen in portrait, landscape or both. Don't rely on locking the orientation: screen.orientation.lock() isn't available in every major browser, and usually works only on mobile in fullscreen. (MDN, Pointer events: touch-action, MDN, touch-action: accessibility, CrazyGames, Device and browser compatibility, Poki, Requirements, MDN, ScreenOrientation.lock())
  • 6 WEBGAME-11 Read gamepads by polling navigator.getGamepads() once per frame, ask the player to press a button before expecting a controller to appear, and let players remap buttons when a gamepad's mapping isn't "standard". Browsers expose a connected gamepad only after the player presses a button or moves a stick, the API needs HTTPS, and Godot warns that mappings can be wrong for some combinations of browser, operating system and controller. This applies GAMEDEV-18. (MDN, Using the Gamepad API, Godot, Gamepads)
  • 6 WEBGAME-12 Request fullscreen and pointer lock only from a click or key-press handler, handle a refusal, and check that the page embedding the game allows them. Both need a recent user interaction: Unity defers the request to the next input event, so trigger it on mouse-down or key-down rather than on release, and Godot needs it inside an input event callback. A cross-origin iframe needs allow="fullscreen", and a sandboxed iframe needs allow-pointer-lock. For aiming, request pointer lock with unadjustedMovement: true to get raw mouse input where the browser supports it. (MDN, requestFullscreen(): security considerations, MDN, Pointer Lock API, Unity, Input in Web, Godot, Full screen and mouse capture)

Saving

Publishing

  • 6 WEBGAME-14 If you publish on web game portals, integrate each portal's SDK and meet its technical requirements from the start: report loading and gameplay events, show ads only through the portal's SDK, and bundle every asset into the build. Poki blocks external requests, allows no other ad system, requires the game to mute its audio during ads and to stay playable with an ad blocker, and checks that gameplayStart() and gameplayStop() fire at the right moments. CrazyGames measures the initial download up to its gameplay-start event, and its data module syncs saves to the player's account. (Poki, Requirements, CrazyGames, SDK integration, CrazyGames, Data module)

Performance

  • 7 WEBGAME-15 Free GPU resources explicitly when a level or scene ends: in three.js, call dispose() on geometries, materials, textures and render targets, and in Phaser, remove assets that only the finished scene used. three.js doesn't release WebGL buffers, textures and shader programs automatically, and MDN advises deleting WebGL objects eagerly rather than waiting for the garbage collector. In three.js, watch renderer.info.memory for leaks. (three.js manual, How to dispose of objects, MDN, WebGL best practices: delete objects eagerly, Phaser, Loader: where to load assets)
  • 6 WEBGAME-16 Profile web builds in the browser on the slowest device you support, and move heavy work that doesn't draw, such as pathfinding or procedural generation, to Web Workers. Use the DevTools Performance panel for main-thread time, with CPU throttling when you profile on a desktop; Spector.js to capture WebGL frames, which RenderDoc can't (GFX-4); and the engine's profiler on a development build, because Unity's Frame Debugger doesn't work on the web. Transfer ArrayBuffers to workers instead of copying them, and render from a worker with OffscreenCanvas where the engine supports it. This applies GAMEDEV-12. (Chrome DevTools, Analyze runtime performance, Spector.js, Unity, Profile a Web build, MDN, Transferable objects, web.dev, OffscreenCanvas)

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 6 Lighthouse CI: resource-summary:total:size and resource-summary:total:count assertions fail CI when the transfer size or number of requests of a page load exceed your budget. Point it at the game's page to check what the loader downloads before play starts. Partly checks WEBGAME-5.
  • 4 ESLint no-restricted-globals: list localStorage with checkGlobalObject: true to flag every use, including window.localStorage, in your own code. Partly checks WEBGAME-13.

Tutorials and further reading

  • 6 Game development tutorials (MDN): step-by-step series that build a breakout game with the Canvas API and with Phaser, a Phaser platformer, and a mobile maze game that uses device orientation.
  • 6 Implementing game control mechanisms (MDN): one game made playable with touch, mouse and keyboard, and gamepads.