ampproject / ampproject/amphtml
Lazy load embed bento components to improve performance
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Description
All the bento components with embeds load all the required scripts for embeds on the page load which affects the performance of the page and reduces page insights score.

This can be avoided by lazy loading the embed components such as Twitter, Youtube, Soundcloud. Etc using the first user scroll action or loading component when it comes in the viewport using the intersection observer when the embed is below the fold. This will prevent the third-party embed scripts from blocking the main thread on page load.
### Reproduction Steps
- Open https://bento-twitter.glitch.me/
- The twitter.js and widget.js can be seen loaded on the page load in the dev console and it will block the main thread.
### Relevant Logs
_No response_
### Browser(s) Affected
_No response_
### OS(s) Affected
_No response_
### Device(s) Affected
_No response_
### AMP Version Affected
_No response_
Contributor guide
Research direction
Start by reproducing the issue at bento-twitter.glitch.me and inspect the browser dev console for twitter.js and widget.js during page load. Review the bento components with embeds and determine how loading can be deferred until the first scroll or viewport entry. Done means the third-party embed scripts no longer block the initial page load while the embeds still load when needed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend, performance
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100