Web Systems & Interactive Sites

How to Lazy-Load a Three.js Scene Without Hurting LCP

A loading pattern for 3D hero sections: a real poster image for LCP, Three.js fetched only when the visitor can see it, and rendering that pauses when they scroll away.

10 November 2026 · 6 min read · TOSS
TOSS illustration for How to Lazy-Load a Three.js Scene Without Hurting LCP

A 3D hero section is usually the slowest thing on the page, and it is usually the first thing on the page. That combination is what wrecks Largest Contentful Paint (LCP), the Core Web Vitals metric for how quickly the main content appears.

The fix is not to drop the 3D. It is to change what loads first. The visitor should see a finished-looking hero straight away, and the Three.js scene should arrive a moment later and take over without anyone noticing the swap.

Why the canvas is not your LCP element

LCP only measures certain element types: images, images inside SVG, video posters, elements with a CSS background image, and blocks of text. A <canvas> is not on that list.

So when your hero is a WebGL canvas, LCP falls on something else, usually the headline. That sounds harmless until you look at what the browser is doing in the meantime. It is downloading the Three.js bundle, parsing it, compiling shaders, fetching a 3D model and decoding textures. All of that competes with the headline, the font and the CSS for bandwidth and for the main thread. The headline paints late, and LCP goes with it.

The canvas does not count, but everything it drags in does.

The pattern: poster first, scene later

Three parts:

  1. A real <img> poster in the hero, rendered from the same scene, marked as high priority. This becomes the LCP element and loads fast.
  2. Three.js loaded with a dynamic import(), so it lives in its own file and is not part of the page’s main JavaScript.
  3. That import triggered only when the hero is visible and the browser has finished its first round of work.

Here is the markup:

<section class="hero">
  <div class="hero-3d" data-scene>
    <img
      src="/images/hero-poster.webp"
      width="1600" height="900"
      alt="Rendered view of the product from the front"
      fetchpriority="high"
      class="hero-poster"
    />
  </div>
  <h1>Your headline here</h1>
</section>

Give the container fixed dimensions in CSS (an aspect-ratio works well) so nothing shifts when the canvas appears. A layout jump at this point would trade an LCP problem for a Cumulative Layout Shift problem.

The loader script

// hero-loader.js
const container = document.querySelector('[data-scene]');

function shouldSkip3D() {
  const reducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
  const saveData = navigator.connection?.saveData === true;
  return reducedMotion || saveData;
}

function whenIdle(fn) {
  if ('requestIdleCallback' in window) {
    requestIdleCallback(fn, { timeout: 2000 });
  } else {
    setTimeout(fn, 200);
  }
}

if (container && !shouldSkip3D()) {
  const observer = new IntersectionObserver((entries) => {
    if (entries.some((e) => e.isIntersecting)) {
      observer.disconnect();
      whenIdle(async () => {
        const { mountScene } = await import('./hero-scene.js');
        mountScene(container);
      });
    }
  }, { rootMargin: '200px' });

  observer.observe(container);
}

A few decisions in there are deliberate.

requestIdleCallback is not available in every major browser, so the fallback matters. The timeout makes sure the scene still loads on a busy page instead of waiting forever.

Visitors who ask for reduced motion, or who have turned on a data saver, keep the poster. They get a good page, just a still one. navigator.connection is also missing in some browsers, which is why the optional chaining is there.

The rootMargin starts the load slightly before the hero scrolls into view, which matters when the 3D sits further down the page.

The scene module

This is where Three.js is imported. Because it is only reached through the dynamic import above, your bundler splits it into a separate chunk.

// hero-scene.js
import * as THREE from 'three';
import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';

export async function mountScene(container) {
  const { width, height } = container.getBoundingClientRect();

  const renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
  renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
  renderer.setSize(width, height);

  const scene = new THREE.Scene();
  const camera = new THREE.PerspectiveCamera(35, width / height, 0.1, 100);
  camera.position.set(0, 0, 6);
  scene.add(new THREE.AmbientLight(0xffffff, 1.5));

  const gltf = await new GLTFLoader().loadAsync('/models/product.glb');
  scene.add(gltf.scene);

  const render = () => {
    gltf.scene.rotation.y += 0.003;
    renderer.render(scene, camera);
  };

  // Render one frame before showing the canvas, so there is no blank flash.
  render();
  renderer.domElement.classList.add('hero-canvas');
  container.appendChild(renderer.domElement);
  requestAnimationFrame(() => container.classList.add('is-live'));

  // Only animate while the hero is on screen.
  new IntersectionObserver(([entry]) => {
    renderer.setAnimationLoop(entry.isIntersecting ? render : null);
  }).observe(container);
}

And the CSS that handles the hand-over:

.hero-3d { position: relative; aspect-ratio: 16 / 9; }
.hero-poster, .hero-canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.hero-canvas { opacity: 0; transition: opacity 0.4s ease; }
.hero-3d.is-live .hero-canvas { opacity: 1; }

The poster stays underneath. If WebGL fails, the model 404s or the script throws, the visitor still sees a complete hero. That fallback costs nothing and protects the page on old phones.

Capping the pixel ratio at 2 is worth its own mention. Some phones report 3, and rendering at that density can more than double the pixel count for a difference nobody sees on a moving object.

Shrinking what the scene loads

Lazy loading moves the cost. It does not remove it. Once the pattern is in place, the next win is the model itself. Export as GLB, compress the geometry with Draco or Meshopt (Three.js has a loader for each), and size textures to how large they actually appear on screen. A 4K texture on an object that fills a third of a laptop screen is wasted download.

Checking that it worked

Open Chrome DevTools, go to the Network panel, and reload with the hero off-screen or with throttling on. The Three.js chunk and the .glb file should not appear until the scene is triggered.

Then run a Performance recording. The LCP marker should point at the poster image, and it should land well before the Three.js chunk finishes downloading. If the chunk still appears in the first few requests, something is importing three statically. Search the codebase for a stray import ... from 'three' outside the scene module.

On an Astro site, put the loader in a <script> tag inside the hero component. Astro bundles it, and Vite splits the dynamic import into its own file without extra configuration.

When to load sooner

If the 3D is the product, as with a configurator where the visitor came specifically to rotate and customise something, waiting for idle time can feel sluggish. Keep the poster for LCP, but drop the idle wait and start the import as soon as the poster’s load event fires. The principle stays the same: let the content that counts paint first.

This is the kind of detail we build into every interactive site at TOSS. If you want a 3D or interactive website that also scores well on Core Web Vitals, see our web systems service or get a quote.

Talk to TOSS

Turn the idea into a working system.

Start with the friction. We will help you find the right system.

Start a conversation →