What does a buyer see if their phone can't run WebGL, or the signal is slow and the 3D model hasn't arrived yet? If the answer is "an empty box", the page isn't done. A good 3D page still works when its 3D is slow, heavy, or can't show at all. A stunning scene alone isn't enough.
Picture Raka's shop window with a spotlight: the light makes the mug look amazing, but if it goes out, the mug, the price tag and the till are all still there. On the web, 3D is that spotlight: an extra, not a requirement.
The last lesson of this track brings everything together on Raka's product page: the 3D display (the mug and the shirt box), with a performance budget, staged loading, a fallback without WebGL, and accessibility.
The performance budget
Count before adding anything. For Raka's display (numbers from renderer.info in three.js 0.186):
| What is counted | Raka's display | How |
|---|---|---|
| Draw calls | 10 | 1 per mesh per material group: mug body 3 + handle 1 + shirt box 6 |
| Triangles | 1,228 | 192 (48-segment body) + 1,024 (handle) + 12 (box) |
| Texture memory | 2.28 MB | (942 × 300 + 480 × 300) × 4 bytes × 4/3 for mipmaps |
| Canvas pixels | 307,200 | 640 × 480 at DPR 2, with setPixelRatio(Math.min(devicePixelRatio, 2)) |
- A draw call is one drawing command from the CPU to the GPU. Hundreds of draw calls overwhelm a phone's CPU before its GPU is even busy. Cut them by merging geometry that shares a material (
BufferGeometryUtils.mergeGeometries),InstancedMeshfor many identical objects (100 mugs = 1 draw call), and one combined texture (an atlas) so the shirt box needs 1 material, not 6. - Texture memory comes from the pixel size, not the file size: the mug's print PNG is only 14 KB, but on the GPU it becomes 1.5 MB. A single 4096 × 4096 texture is already about 89 MB.
renderer.info.memory.texturesshows 3 here: our two textures plus a 16 × 16 table that MeshStandardMaterial uses.
GPU limits on phones
renderer.capabilities.maxTextureSize(fromMAX_TEXTURE_SIZE): WebGL 2 guarantees at least 2048. Larger textures are shrunk by three.js with the warningTHREE.WebGLRenderer: Texture has been resized from (...) to (...). For phones, use 2048 at most.- When GPU memory runs out, the browser can take the context away: the
webglcontextlostevent. Catch it, callpreventDefault(), and show the poster again. - Phones heat up fast: cap the DPR at 2, stop the loop when the display is off screen (
IntersectionObserver), and don't render when nothing changes.
Loading: GLB, compression, placeholders
Say Raka puts import * as THREE from 'three' straight into the product page's main bundle. three.js for this scene, bundled and minified, is 538 KB, 134.6 KB after gzip (measured with three 0.186.1). Lighthouse's mobile setting is 1.6 Mbps with a 150 ms RTT and a CPU 4 times slower: the download takes about 0.81 seconds, then running three.js plus the first render makes one long task of about 130 ms (measured in Chrome), adding about 80 to 110 ms of TBT. So three.js is split off with import() and only loaded when needed:
// index.js: the product page, without three.js
import WebGL from 'three/addons/capabilities/WebGL.js'; // just a small checker
async function load3D() {
const { buildDisplay } = await import('./display-3d.js'); // a separate chunk: three.js
await buildDisplay(document.getElementById('shop-3d'));
}
if (WebGL.isWebGL2Available()) load3D(); // or when the "View in 3D" button is clicked
3D models usually come as glTF, in one binary file as .glb. Raka's display exports to 66.4 KB (38.6 KB of geometry, the rest PNG textures). A scanned model or one made in Blender can be several MB, and there are two ways to shrink its geometry:
- Draco (the
KHR_draco_mesh_compressionextension): usually the smallest, but it needsDRACOLoaderand a WebAssembly decoder of about 75 KB gzip that runs in a Worker. - Meshopt (
EXT_meshopt_compression):loader.setMeshoptDecoder(MeshoptDecoder), its decoder is only 7.7 KB gzip and decodes faster.
For a 66 KB model, the Draco decoder is bigger than what it saves; for a 5 MB scan, compression makes a real difference. Both can be produced with npx @gltf-transform/cli draco or meshopt.
const loader = new GLTFLoader().setMeshoptDecoder(MeshoptDecoder);
const gltf = await loader.loadAsync('/model/display.glb', (e) => {
container.dataset.percent = Math.round((e.loaded / e.total) * 100); // "Loading 42%"
});
scene.add(gltf.scene);
Meanwhile visitors must see something: a model can be large, and an empty canvas looks like a broken page. The best placeholder is a poster image of the products in a box whose size is already reserved (aspect-ratio: 4 / 3), plus a percentage from onProgress. When the 3D is ready, the poster is swapped for the canvas in the same place: nothing moves. In R3F, wrap the model in <Suspense fallback={...}>; drei's useProgress gives the percentage.
Without WebGL: progressive enhancement
Progressive enhancement means the basic page (images, text, prices, the buy button) works in every browser, and the 3D is only added when it can be. three.js needs WebGL 2 since r163; without it new THREE.WebGLRenderer() throws THREE.WebGLRenderer: Error creating WebGL context. So check first:
<a class="skip" href="#detail">Skip the 3D, go to the product details</a>
<div id="shop-3d" style="aspect-ratio: 4 / 3; max-width: 320px">
<img id="poster" src="/img/display.webp" width="320" height="240"
alt="A black Coffee Print Mug with the coffee-cup print, next to the Coffee Print Tee box">
</div>
<h2 id="detail" tabindex="-1">Product details</h2>
If WebGL.isWebGL2Available() is false, load3D is never called: the poster and the prices stay, and the 134.6 KB of three.js is never downloaded.
Accessibility
- Alt text for the canvas:
canvas.setAttribute('role', 'img')and anaria-labelthat describes what it shows. A screen reader can't see inside a canvas. - A "Skip the 3D" link at the start of that section, pointing at the product details heading (
tabindex="-1"so it can take focus): keyboard users don't have to get past the canvas and all its buttons. - Reduced motion:
controls.autoRotate = !matchMedia('(prefers-reduced-motion: reduce)').matches. - Keyboard: plain buttons to turn the camera and pick a product (the Interactive Three.js lesson).
The effect on Lighthouse
Lighthouse 13's performance score weighs TBT 30%, LCP 25%, CLS 25%, FCP 10% and Speed Index 10%. For a 3D page:
- TBT: three.js's long task counts if it loads when the page opens. Load it when visible or on click.
- LCP: a
<canvas>is never an LCP candidate (images and blocks of text are). A small poster<img>or the product heading becomes the LCP, so make it show quickly. - CLS: a box whose size is reserved from the start keeps CLS at 0 when the 3D appears.
Plain three.js or R3F
If Raka's shop is already built with React, React Three Fiber is the right choice: the scene is written as components, the cart state and the chosen colour become props directly, and drei provides helpers. If the page is static with no React, plain three.js is lighter. On the GPU both draw the same thing; what decides is the draw calls, the triangles, the textures and how it loads.
Other options, including one with no 3D code for a single .glb model that can be turned:
| Way | When to pick it |
|---|---|
| Plain three.js (the code in this lesson) | a page with no React, or a scene with behaviour of its own: clicking products, changing colours, animation |
| React Three Fiber | the site already uses React |
<model-viewer> 4.4.0 (a web component) |
one model without writing 3D code. alt becomes the label for screen readers, poster shows while it waits, the model loads only when it comes near the screen, and camera-controls lets people turn it with the mouse, touch and the arrow keys. The file is about 290 KB gzip, twice the three.js of this scene, because three.js is inside it |
One page from twelve lessons
| Part of the page | From the lesson |
|---|---|
| The coffee print on the texture and the poster | Canvas API Basics |
| Coffee steam, time deltas | Canvas Animation |
| Pointer, drag | Interactive Canvas |
| The moving shop logo | SVG Animation |
| The Bean Pattern motif for the next shirt | Generative Art |
| Shaders, DPR, resizing | WebGL Concepts, Three.js Setup |
The mug, the box, lights, dispose() |
Three.js Geometry & Material |
The loop, Timer, autoRotate with a delta |
Three.js Animation |
| Orbit, raycaster, keyboard buttons | Interactive Three.js |
| The React version | React Three Fiber |
| Budget, loading, fallback, accessibility | this lesson |
⚠️ Check these before the 3D display goes live
- three.js in the main bundle: 134.6 KB gzip and a 130 ms long task on a phone, even though the 3D is further down. Use
import(). - A 3D box with no size and no poster: an empty screen while loading, then the price text gets pushed down (CLS).
- 4096 textures for phones: 89 MB of GPU memory per texture, or quietly shrunk. Use 2048 at most.
- No WebGL check: on a device without WebGL 2, the page errors or stays blank.
- A canvas with no alt text and no skip link: screen reader and keyboard users get lost.
TL;DR: 3D is an extra, not a requirement. Count the budget: draw calls (1 per mesh per material group, cut with merging, InstancedMesh, an atlas), triangles, texture memory (width × height × 4 × 4/3; Raka's display: 10 draw calls, 1,228 triangles, 2.28 MB), DPR at most 2, textures at most 2048 on phones, handle webglcontextlost. Split three.js (134.6 KB gzip) off with import() and load it when visible or clicked; .glb models with GLTFLoader, Draco (KHR_draco_mesh_compression) or Meshopt (EXT_meshopt_compression) compression. A poster <img> with alt text in an aspect-ratio box as the placeholder, and as the fallback when WebGL.isWebGL2Available() is false. Canvas role="img" + aria-label, a "Skip the 3D" link, prefers-reduced-motion. Lighthouse: TBT 30%, LCP 25% (a canvas is never a candidate), CLS 25%. Already React? R3F; not? Plain three.js.
⚡ 3D is an extra, not a requirement
Meaning: A good page still works when its 3D is slow, heavy, or can't show at all. The price, the buy button, and a poster <img> with alt text in an aspect-ratio: 4 / 3 box are there before three.js arrives.
⚡ Count the budget
Guess first: the mug's print PNG is only 14 KB. How big is it on the GPU?
About 1.5 MB. Texture memory comes from the pixel size, not the file size.
Meaning: A draw call is 1 per mesh per material group, and a texture takes width × height × 4 × 4/3 bytes. Raka's display: 10 draw calls, 1,228 triangles, 2.28 MB. For phones, textures are 2048 at most.
⚡ Load three.js later
Write:
async function load3D() {
const { buildDisplay } = await import('./display-3d.js'); // a separate chunk: three.js
await buildDisplay(document.getElementById('shop-3d'));
}
if (WebGL.isWebGL2Available()) load3D();
Meaning: three.js (134.6 KB gzip) is split off with import() and only downloaded when needed. Without WebGL 2, the poster and the prices stay, and three.js is never downloaded.
⚡ Plain three.js or R3F?
Meaning: If the site already uses React, React Three Fiber is the right choice: the scene becomes components, and state becomes props directly. A static page with no React is lighter with plain three.js. On the GPU, both draw the same thing.