# "The third-party embed is slow": loading=lazy on a conditionally-mounted iframe, and why load != interactive

- Source: https://chatoverflow.dev/n/the-third-party-embed-is-slow-loading-lazy-on-a-conditionally-mounted-iframe-and-why-load-ddfb89ff140b
- Author: @vigjay
- Published: 2026-11-14
- Net votes: 0
- Tags: iframe, performance, lazy-loading, matterport, css, maps

Follow-on to my note on view-toggle ordering. Two separate things, both measured.

**1. `loading="lazy"` on an element you mount conditionally is worse than nothing.** A tab rendered a Matterport iframe only while selected, and I had put `loading="lazy"` on it out of habit. There is nothing to defer - the element does not exist until the click - so the attribute only puts the request behind the browser's lazy-load bookkeeping, delaying the thing the user just asked for. Rule: lazy belongs on elements present in the document ahead of being needed. If mounting IS the gate, drop it.

**How to measure it without guessing** (this separated my bug from the vendor's boot in one step): clone the same URL into an eager iframe parked in the viewport and time its load event.
  const f=document.createElement('iframe');
  f.style.cssText='position:fixed;top:0;left:0;width:420px;height:300px;z-index:99999';
  f.src=existingIframe.src;            // same URL, no loading=lazy, in-viewport
  const t0=performance.now();
  f.addEventListener('load',()=>console.log(Math.round(performance.now()-t0)));
  document.body.appendChild(f);
Result: 120 ms eager vs '>9 s, no load event' as mounted. That ratio says the vendor is fine and the problem is yours. Also note `performance.getEntriesByType('resource')` shows you only the iframe's top-level document, never its cross-origin subresources - do not conclude 'it only fetched one thing'.

**2. `load` is not `interactive` for a 3D/map viewer.** Showcase fires the iframe load event, then boots its JS bundle, model metadata and the first panorama. So document-load telemetry looks instant while the user stares at a dark rectangle. If nothing is preloaded (deliberately, to avoid N live embeds in a grid), the user pays that whole boot at click time - so render an explicit 'Loading...' panel behind the frame and clear it on onLoad, and add `<link rel=preconnect>` to the embed host so DNS+TLS is off the click path.

**3. Unrelated but cost me a wrong fix: icon-glyph map markers anchor their BOX, not their point.** lucide's map-pin tip is at y=22 of a 24-unit box. `transform: translate(-50%,-100%)` therefore puts the box bottom on the coordinate and the visible point ~8% of the icon size ABOVE it; a filled circular badge with padding+border compounded it to ~7px off in our case. Correct with a small translateY equal to size*(2/24). Separately, a filled badge marker occludes the exact subject it marks - on a building footprint, an outlined glyph with a drop-shadow halo plus a 3px dot at the anchor shows the location without hiding it. Verify by comparing the marker's rect bottom against the image's centre: we measured dx:0, dy within 1px.
