Web Browser Game Development
Framework selection and browser-specific principles. For stack choice details see game-development/engine-selection.
1. Framework Selection
Decision Tree
What type of game?
│
├── 2D Game
│ ├── Full game engine features? → Phaser 4
│ ├── Fast prototype / jam? → Kaplay
│ ├── Raw rendering power? → PixiJS 8
│ └── Tiny / no dependency? → Raw Canvas / WebGL
│
├── 3D Game
│ ├── Full engine (physics, XR)? → Babylon.js
│ └── Rendering focused? → Three.js
│
├── Hybrid (DOM UI + canvas moments)
│ └── Custom shell + guest viewport
│ (Canvas/Kaplay/Phaser/Pixi inside a region/modal)
│
└── Narrative-first
└── Ink (inkjs) or Twine export + DOM host
Comparison
| Framework |
Type |
Best For |
| Raw Canvas / WebGL |
2D / low-level |
Small scope, full control |
| Kaplay |
2D toolkit |
Rapid prototypes |
| Phaser 4 |
2D engine |
Full game features |
| PixiJS 8 |
2D renderer |
Rendering, custom systems |
| Three.js |
3D renderer |
Visualizations, lightweight 3D |
| Babylon.js |
3D engine |
Full engine, XR |
Hybrid shell + guest
Use when chrome is HTML (menus, inventories, text, dashboards) but bursts of play need a canvas:
- Mount guest in a container; pass context in.
- Run a local game loop in the guest.
- Return results (score, pass/fail); destroy guest (RAF, listeners, GL context as needed).
Do not let the guest own global app routing unless the product is a full-screen game.
2. WebGPU Adoption
Browser Support (2025)
| Browser |
Support |
| Chrome |
✅ Since v113 |
| Edge |
✅ Since v113 |
| Firefox |
✅ Since v131 |
| Safari |
✅ Since 18.0 |
| Total |
~73% global |
Decision
- New GPU-heavy projects: Use WebGPU with WebGL fallback
- Broad legacy / simple 2D: Start with WebGL or Canvas 2D
- Feature detection: Check
navigator.gpu
3. Performance Principles
Browser Constraints
| Constraint |
Strategy |
| No local file access |
Asset bundling, CDN |
| Tab throttling |
Pause when hidden (visibilitychange) |
| Mobile data limits |
Compress assets |
| Audio autoplay |
Require user interaction |
Optimization Priority
- Asset compression - KTX2, Draco, WebP
- Lazy loading - Load on demand
- Object pooling - Avoid GC
- Draw call batching - Reduce state changes
- Web Workers - Offload heavy computation
4. Asset Strategy
| Type |
Format |
| Textures |
KTX2 + Basis Universal (or WebP/PNG for simple 2D) |
| Audio |
WebM/Opus (fallback: MP3) |
| 3D Models |
glTF + Draco/Meshopt |
| Phase |
Load |
| Startup |
Core assets, <2MB |
| Gameplay |
Stream on demand |
| Background |
Prefetch next level |
5. PWA for Games
Benefits: offline play, install, fullscreen, optional push.
Requirements: service worker, web app manifest, HTTPS.
6. Audio Handling
- Create/resume
AudioContext on first click/tap
- Prefer Web Audio API; pool sources; preload common SFX
- Compress with WebM/Opus when possible
7. Anti-Patterns
| ❌ Don't |
✅ Do |
| Load all assets upfront |
Progressive loading |
| Ignore tab visibility |
Pause when hidden |
| Block on audio load |
Lazy load audio |
| Skip compression |
Compress everything |
| Assume fast connection |
Handle slow networks |
| Leave canvas engines running off-screen |
Tear down guests |
Remember: Browser is the most accessible platform. Respect its constraints.
When to Use
Use when building HTML5/WebGL/WebGPU games, choosing a browser runtime, or wiring hybrid DOM+canvas guests.
Limitations
- Use this skill only when the task clearly matches the scope described above.
- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
1---2name: web-games3description: Web browser game development. Framework selection (Phaser, PixiJS, Kaplay, Canvas/WebGL, Three.js, Babylon.js), hybrid DOM+canvas, WebGPU, optimization, PWA, audio unlock. Use when building HTML5/WebGL/WebGPU games or choosing a browser runtime.4---56# Web Browser Game Development78> Framework selection and browser-specific principles. For stack choice details see `game-development/engine-selection`.910---1112## 1. Framework Selection1314### Decision Tree1516```17What type of game?18│19├── 2D Game20│ ├── Full game engine features? → Phaser 421│ ├── Fast prototype / jam? → Kaplay22│ ├── Raw rendering power? → PixiJS 823│ └── Tiny / no dependency? → Raw Canvas / WebGL24│25├── 3D Game26│ ├── Full engine (physics, XR)? → Babylon.js27│ └── Rendering focused? → Three.js28│29├── Hybrid (DOM UI + canvas moments)30│ └── Custom shell + guest viewport31│ (Canvas/Kaplay/Phaser/Pixi inside a region/modal)32│33└── Narrative-first34 └── Ink (inkjs) or Twine export + DOM host35```3637### Comparison3839| Framework | Type | Best For |40|-----------|------|----------|41| **Raw Canvas / WebGL** | 2D / low-level | Small scope, full control |42| **Kaplay** | 2D toolkit | Rapid prototypes |43| **Phaser 4** | 2D engine | Full game features |44| **PixiJS 8** | 2D renderer | Rendering, custom systems |45| **Three.js** | 3D renderer | Visualizations, lightweight 3D |46| **Babylon.js** | 3D engine | Full engine, XR |4748### Hybrid shell + guest4950Use when chrome is HTML (menus, inventories, text, dashboards) but bursts of play need a canvas:51521. Mount guest in a container; pass context in.532. Run a **local** game loop in the guest.543. Return results (score, pass/fail); **destroy** guest (RAF, listeners, GL context as needed).5556Do not let the guest own global app routing unless the product *is* a full-screen game.5758---5960## 2. WebGPU Adoption6162### Browser Support (2025)6364| Browser | Support |65|---------|---------|66| Chrome | ✅ Since v113 |67| Edge | ✅ Since v113 |68| Firefox | ✅ Since v131 |69| Safari | ✅ Since 18.0 |70| **Total** | **~73%** global |7172### Decision7374- **New GPU-heavy projects**: Use WebGPU with WebGL fallback75- **Broad legacy / simple 2D**: Start with WebGL or Canvas 2D76- **Feature detection**: Check `navigator.gpu`7778---7980## 3. Performance Principles8182### Browser Constraints8384| Constraint | Strategy |85|------------|----------|86| No local file access | Asset bundling, CDN |87| Tab throttling | Pause when hidden (`visibilitychange`) |88| Mobile data limits | Compress assets |89| Audio autoplay | Require user interaction |9091### Optimization Priority92931. **Asset compression** - KTX2, Draco, WebP942. **Lazy loading** - Load on demand953. **Object pooling** - Avoid GC964. **Draw call batching** - Reduce state changes975. **Web Workers** - Offload heavy computation9899---100101## 4. Asset Strategy102103| Type | Format |104|------|--------|105| Textures | KTX2 + Basis Universal (or WebP/PNG for simple 2D) |106| Audio | WebM/Opus (fallback: MP3) |107| 3D Models | glTF + Draco/Meshopt |108109| Phase | Load |110|-------|------|111| Startup | Core assets, <2MB |112| Gameplay | Stream on demand |113| Background | Prefetch next level |114115---116117## 5. PWA for Games118119**Benefits:** offline play, install, fullscreen, optional push.120**Requirements:** service worker, web app manifest, HTTPS.121122---123124## 6. Audio Handling125126- Create/resume `AudioContext` on first click/tap127- Prefer Web Audio API; pool sources; preload common SFX128- Compress with WebM/Opus when possible129130---131132## 7. Anti-Patterns133134| ❌ Don't | ✅ Do |135|----------|-------|136| Load all assets upfront | Progressive loading |137| Ignore tab visibility | Pause when hidden |138| Block on audio load | Lazy load audio |139| Skip compression | Compress everything |140| Assume fast connection | Handle slow networks |141| Leave canvas engines running off-screen | Tear down guests |142143---144145> **Remember:** Browser is the most accessible platform. Respect its constraints.146147## When to Use148149Use when building HTML5/WebGL/WebGPU games, choosing a browser runtime, or wiring hybrid DOM+canvas guests.150151## Limitations152153- Use this skill only when the task clearly matches the scope described above.154- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.155- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.