Load webframes lazily

A page can hold hundreds of webframes, most of them inside collapsed
expandables. The source is attached on mount, so every one of them starts
a cross-origin navigation as soon as the page hydrates: a reference page
with 521 webframes fired 521 requests, the last finishing ~20s in.

Mark the iframe `loading="lazy"` so each one waits until it is near the
viewport. An iframe inside a collapsed `<details>` then loads nothing, and
loads on open.
This commit is contained in:
taranvohra
2026-10-29 22:04:20 +05:30
parent ea018507c7
commit 3c92aa49a4
@@ -196,6 +196,10 @@ export function ElementWebframe(props: ContentKitClientElementProps<ContentKitWe
// Rendered without a source before mount so it reserves its size in the SSR layout.
src={mounted ? element.source.url : undefined}
title={element.source.url}
// A page can hold hundreds of these, most of them inside collapsed expandables.
// Loading them all on mount delays the first paint by seconds, so each one waits
// until it is near the viewport.
loading="lazy"
allowFullScreen
allow="clipboard-write"
className="contentkit-webframe block h-full w-full max-w-full border-none"