main ← perf/lazy-load-full-app-embed
merged 02:45PM - 16 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
- Default margin of 1000px to give the heavy PWA time to load before the user reaches it
- On by default for `fullApp` embeds, opt out with `lazyLoad: false`
- Configurable margin via `lazyLoadMargin`
- Show options 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. The default 1000px margin gives Discourse a head start on loading before the user actually scrolls to the embed.
```js
DiscourseEmbed = {
discourseUrl: 'https://forum.example.com/',
topicId: 123,
fullApp: true,
// lazyLoad: false, // disable lazy loading of the iframe
// lazyLoadMargin: '1000', // pixels before viewport to start loading
};
```
## 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
- [ ] Custom `lazyLoadMargin` — verify the margin is respected
- [ ] Standard (non-full-app) embed — verify unchanged behavior (always loads immediately)
- [ ] Browser without IntersectionObserver — verify falls back to immediate loading