Kim Angelo Gagui logo

Websites, web applications and technical SEO

Loading a 3D interaction only when it is needed

How I keep the contact form ready while loading its 3D envelope only when someone chooses to interact.

A small interaction can make a website feel more personal. It can also bring a surprising amount of work into the browser. The contact envelope on this portfolio is a useful example: the paper folds use Three.js, but reading the homepage does not require a 3D renderer.

The implementation now starts with a static envelope image and a working contact link. Mouse or pen hover, or keyboard focus, can prepare the 3D scene. A touch visitor can open the HTML contact form immediately.

A closed paper envelope inviting the visitor to start a conversation.
The static envelope is available before the 3D scene is needed.

Separate the invitation from the animation

The important job is helping someone contact me. The animation is one way to present that journey, so the interface needs a useful starting point before it loads.

The envelope is an ordinary link to the contact page. After the page becomes interactive, it can open an accessible dialog containing the same inquiry form. Without JavaScript, the link still reaches the contact page and its alternative contact information.

This gives the experience three useful layers:

  1. A static image and a real link in the initial page.
  2. An HTML form for entering and sending a message.
  3. A 3D presentation prepared after hover or keyboard intent.

The contact journey should remain useful while the visual enhancement is unavailable or still loading.

A dynamic import still needs the right trigger

Splitting the scene into a separate JavaScript chunk is a good start. However, automatically requesting that chunk shortly after page load still makes ordinary visitors download and initialize it.

The important change is deciding when to call the import. A simplified version looks like this:

async function prepareEnvelope() {
  const { createEnvelopeScene } = await import('./envelope-scene');
  // Create the scene only when the interface is still ready for it.
}

trigger.addEventListener('pointerenter', prepareEnvelope);

The actual implementation also checks reduced-motion and data-saving preferences, avoids repeated initialization, and handles the case where the component is removed while the import is still pending. Touch opening uses the HTML form rather than waiting for the scene.

This is a deliberate tradeoff. A visitor who clicks before preparation finishes can see the form immediately. They do not have to wait for the unfolding effect to complete its setup.

Keep background work tied to an interaction

Loading is only part of the cost. An interface can also do unnecessary work through event listeners and layout measurements.

For the envelope, hover movement stays on its trigger element. Geometry reads are grouped into an animation frame, so several pointer events do not each require a separate measurement. Window-level movement listeners are attached during a drag and removed when that drag finishes or is cancelled.

The dialog follows the same principle. It listens for viewport changes while open, which lets the sheet adjust to a smaller mobile viewport. Those listeners are removed when it closes.

Visitor actionWork the interface needs
Read the homepageShow the static envelope and contact link.
Hover or focus the envelopePrepare the optional 3D scene.
Tap on a touch deviceOpen the HTML form immediately.
Drag the prepared envelopeTrack movement until release or cancellation.
Resize an open dialogAdjust the form to the available viewport.

Test the complete contact journey

Reducing startup work is useful only if the experience still works. The checks need to include the paths that an animation can easily interrupt:

  • Opening and closing with a mouse, a keyboard, and touch.
  • Reversing a partial drag and releasing outside the original trigger.
  • Keeping keyboard focus inside the open dialog and returning it on close.
  • Preserving an unfinished message after closing and reopening.
  • Showing an error without clearing the draft when delivery fails.
  • Showing the sent state only after the server confirms delivery.

The browser network panel also provides a direct check: an ordinary visit should not request the envelope scene chunks. Hover or keyboard focus should request them when that enhancement becomes relevant.

Measure the work, then measure the result

The useful questions are concrete. Which resource is the largest visible element? Which tasks block the browser? Is the page requesting code that the visitor has not used?

For this homepage, the static envelope image can be given high fetch priority while the animation waits for intent. That addresses image delivery and JavaScript startup as separate concerns. It does not replace checking the finished site under representative mobile conditions.

Lighthouse results can vary between runs. A new production measurement is needed before claiming an improvement to a particular score or loading time. The implementation change is easier to verify directly: the 3D scene is no longer part of an ordinary visit's startup work.

For the measurement concepts, see Chrome's explanations of Total Blocking Time and LCP request discovery.

You can explore the project case studies for more context on the websites and applications in this portfolio.

This is also the kind of implementation work I cover in my technical SEO audits and improvements: identify unnecessary browser work, make a focused change, and verify the contact journey still works.