Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 18.4 — Core Web Vitals and Lazy Canvases
3D Web · Example 2 of 2

Layout shift: the box with and without reserved space

A is the common mistake. B reserves the canvas's final height before it exists.

A 3D scene is the heaviest thing on most pages. Show a poster picture first, fetch three.js only when the scene is about to be seen, reserve its space, and stop drawing when it scrolls away.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 4 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write whenVisible(element, start) that calls start once, when the element is within 200 px of the viewport.

02

Add a CSS rule so a 16:9 canvas slot is reserved at any width.

Explain it without notes

01

A product page has a 3D viewer below the fold. List four changes that protect LCP, INP and CLS.

02

Why does import("./main.js") make the page lighter than a normal import?

Layout shift: the box with and without reserved space
Press Run to see the page.
idle

Console

Nothing logged yet.

Expected console output

A: no space reserved       paragraph moved by 120 px
B: space reserved          paragraph moved by 0 px