main ← perf/lazy-load-full-app-embed
opened 08:14PM - 15 Apr 26 UTC
## Summary
- Defer loading the Discourse iframe for full app embeds until the u…ser scrolls near it
- Feature detect `IntersectionObserver` — fall back to immediate loading if unavailable
- On by default for `fullApp` embeds, opt out with `lazyLoad: false`
- Show the opt-out option in the admin embedding code snippet
## How it works
The iframe element is appended to the DOM immediately (preserving layout space with `embedHeight`), but its `src` is not set until the `IntersectionObserver` fires with a `200px` root margin. This means the full Discourse app only starts loading when the user is close to scrolling to it, saving significant server and client resources for pages where the embed is below the fold.
```js
DiscourseEmbed = {
discourseUrl: 'https://forum.example.com/',
topicId: 123,
fullApp: true,
// lazyLoad: false, // disable lazy loading of the iframe
};
```
## Test plan
- [ ] Full app embed below the fold — verify iframe doesn't load until scrolling near it
- [ ] Full app embed above the fold — verify it loads immediately (IntersectionObserver fires right away)
- [ ] `lazyLoad: false` — verify immediate loading, same as current behavior
- [ ] Standard (non-full-app) embed — verify unchanged behavior (always loads immediately)
- [ ] Browser without IntersectionObserver — verify falls back to immediate loading