Reduce how much JavaScript and CSS a web game ships. Measure every file's raw and gzip size, find heavy libraries, duplicates, source maps, unminified code, node_modules and dev files in the shipped folder, and CDN dependencies. Then minify and bundle with esbuild or Vite, tree-shake engine imports, code-split levels and editors, swap heavy libraries for small ones, and vendor CDN files for off...
Download skill (.zip) Files on GitHubGame bundle optimization
python3 <skill>/scripts/bundle-report.py www/ # or dist/, or the game root for no-build games
It lists JS / CSS / WASM files by gzip size (what players actually download), and flags shipped source maps, unminified large
files, known heavy libraries with smaller alternatives, the same library shipped twice, node_modules or tests in the shipped
folder, and CDN imports.
Budgets (gzip): < 300 KB of code for a 2D game; < 1 MB with a 3D engine. Assets usually matter more. Check them with game-loading-optimization.
No-build games (plain ES modules, like the game-scaffolding template)
Fine for development and small games. For release:
npx esbuild src/main.js --bundle --minify --format=esm --outfile=www/main.js --sourcemap=external # one file, minified
Point index.html at main.js and copy assets/, index.html and style.css to the shipped folder (www/). Don’t upload
the .map file to portals.
Bundled projects (Vite / esbuild)
- Tree-shake: named imports (
import { Scene, Mesh } from "three"), notimport * as THREEfrom a pre-built UMD file. - Code-split big optional parts with
await import("./editor.js"): level editors, debug tools, rarely used scenes. - Analyze:
npx vite-bundle-visualizeroresbuild --metafile=meta.json+esbuild --analyze. - Drop dev code:
if (import.meta.env.DEV)blocks are removed in production builds. - Targets:
build.target: "es2020"avoids heavy polyfills; all browsers that run WebGL games support it.
Library swaps
| Heavy | Lighter |
|---|---|
| moment | Intl.DateTimeFormat |
| lodash (full) | single imports, or a 3-line helper |
| jQuery | DOM APIs |
| Tone.js for a few sfx | Web Audio (game-sound-design audio.js) |
| Matter.js for simple boxes | your own AABB code (game-physics) |
| Full Phaser for a tiny game | Plain canvas (canvas-2d-rendering), or a custom Phaser build |
CDN imports
Fine on Bash, but itch.io downloads, offline play and some school networks break when a CDN is unreachable, and a CDN
version can change. Vendor pinned copies into the project (vendor/three.module.min.js) for release builds.
Report
“Code: 1.9 MB raw / 520 KB gzip → 640 KB raw / 160 KB gzip (bundled + minified, three.js tree-shaken, maps removed).”