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 aBUTLER_API_KEYsecret. - 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-1Before 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-16andGODOT-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-2Serve the engine's precompressed build files over HTTPS with the matchingContent-Encodingheader,gzipfor.gzandbrfor.brfiles, and serve.wasmfiles asapplication/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.pckand.wasmfiles on the server, and itch.io sets the header from the.gzor.brextension. 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-3Export without threads unless you control the headers of every page that hosts the game. Threads in WebAssembly builds needSharedArrayBuffer, which needs a secure context and cross-origin isolation:Cross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: require-corpon 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-4Ship 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 appliesGFX-13. (Unity, Texture compression in Web, Godot, Export options)
Loading¶
- 8
WEBGAME-5Set a download budget for the first load and for the whole game, from the portals and devices you target, and check every build against it. Poki says the initial download of a good web game shouldn't exceed 5 MB, or 8 MB in total, and that players move to another game when loading takes more than 10 seconds. CrazyGames allows at most 50 MB before gameplay starts, 20 MB for its mobile homepage, and 250 MB and 1,500 files in total; itch.io accepts at most 500 MB, 1,000 files and 200 MB per file. (Poki, Choosing your web game engine, Poki, Requirements, CrazyGames, File size and count limits, itch.io, ZIP file requirements) - 7
WEBGAME-6Download only what the first scene needs before play starts, load the rest per scene in the background, and let the engine cache downloaded files on the player's device. Unity 6.6 adds progressive asset loading; in earlier versions, use Addressables or AssetBundles, and Data Caching keeps the.datafile and AssetBundles in IndexedDB. In Phaser, load shared assets in a boot scene and the others in the scene that uses them. If you write your own service worker, cache each build under a new cache name and delete the old caches when it activates. For mobile store builds, the same rule isMOBGAME-10. (Unity, Reduce Web startup time with progressive asset loading, Unity, Optimize Web platform for mobile, Unity, Cache behavior in Web, Phaser, Loader: where to load assets, MDN, Using Service Workers: deleting old caches)
Game loop and page lifecycle¶
- 7
WEBGAME-7When the page becomes hidden, pause the game, suspend theAudioContextand save progress. Listen forvisibilitychange: the hidden state is often the last change a page can observe, especially on mobile, where closing the tab or the browser fires nopagehideorunload. Browsers stoprequestAnimationFramein 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 emitshiddenandvisibleevents. (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-8If you write your own game loop, drive it withrequestAnimationFrame, request the next frame before doing the frame's work, and advance the fixed time step ofGAMEDEV-1from the callback's timestamp. Don't update onsetIntervalorsetTimeout, which keep using the CPU when the game is minimized and compete with rendering for the main thread.requestAnimationFramefollows the display's refresh rate, commonly 60 Hz but also 120 or 144 Hz, and pauses in background tabs, so keepGAMEDEV-1's cap on steps per frame. (MDN, Anatomy of a video game, MDN, requestAnimationFrame())
Audio and input¶
- 7
WEBGAME-9Start audio from the player's first click, tap or key press, for example on a "tap to play" screen, and resume theAudioContextfrom a later tap whenever it is suspended or interrupted. Browsers block audio until the player has interacted with the page, and anAudioContextcreated 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 avisibilitychangehandler. 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-10Handle mouse, touch and pen with Pointer Events on the game canvas, settouch-action: noneon 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: nonestops 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-11Read gamepads by pollingnavigator.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'smappingisn'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 appliesGAMEDEV-18. (MDN, Using the Gamepad API, Godot, Gamepads) - 6
WEBGAME-12Request 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 needsallow="fullscreen", and a sandboxed iframe needsallow-pointer-lock. For aiming, request pointer lock withunadjustedMovement: trueto 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¶
- 8
WEBGAME-13Store saves in IndexedDB rather thanlocalStorage, request persistent storage when the player first saves, and keep a copy of progress that matters on a server, such as a portal's cloud save or your own backend.localStorageblocks the main thread, holds only about 5 MB of strings, and may be restricted in private browsing, so wrap storage calls intry/catchand keep the game playable without them. Browser storage is best-effort by default: browsers may evict it, Safari deletes script-written data of sites the player hasn't interacted with in seven days of use, and a game in another site's iframe gets storage separate from the same game on your own site. In Godot,OS.is_userfs_persistent()tells you whetheruser://will last. This appliesGAMEDEV-10andGAMEDEV-11. (web.dev, Storage for the web, web.dev, Persistent storage: when to ask, MDN, Storage quotas and eviction criteria, Privacy Sandbox, Storage partitioning, Poki, Requirements, Godot, Using cookies for data persistence, CrazyGames, Data module)
Publishing¶
- 6
WEBGAME-14If 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 thatgameplayStart()andgameplayStop()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-15Free GPU resources explicitly when a level or scene ends: in three.js, calldispose()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, watchrenderer.info.memoryfor leaks. (three.js manual, How to dispose of objects, MDN, WebGL best practices: delete objects eagerly, Phaser, Loader: where to load assets) - 6
WEBGAME-16Profile 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. TransferArrayBuffers to workers instead of copying them, and render from a worker withOffscreenCanvaswhere the engine supports it. This appliesGAMEDEV-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:sizeandresource-summary:total:countassertions 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 checksWEBGAME-5. - 4 ESLint
no-restricted-globals: listlocalStoragewithcheckGlobalObject: trueto flag every use, includingwindow.localStorage, in your own code. Partly checksWEBGAME-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.