ampproject / ampproject/amphtml
Add SSR styling to reduce LCP for `amp-base-carousel` by showing first slide at first paint
- Dominant language
- JavaScript
- Stars
- 14.9k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
### Description
When using `amp-base-carousel`, the contents are hidden until the custom element is built. This results in a negative impact on LCP. Depending on the configuration of the `amp-base-carousel`, what if it could be SSR'ed so that the initial slide were displayed even prior to the element being built? This would greatly reduce LCP by allowing the first slide to be rendered with the initial paint of the page. It would also ensure that the first slide would render even when JavaScript is turned off or the `amp-base-carousel` script fails to download.
Consider this example: https://amp-base-carousel-ssr-styling.glitch.me/
Here's a video showing the page loading without throttling a few times, then a few times on fast 3G, and then a few times on slow 3G:
https://user-images.githubusercontent.com/134745/133321141-d543257c-b5d6-44ec-8087-40b7614a04a0.mov
The styling here applied is:
```css
amp-base-carousel.with-ssr-styling:not(.i-amphtml-built) > *:first-of-type:not(i-amphtml-sizer) {
display: block !important;
color: black !important;
line-height: normal !important;
position: absolute;
top: 0;
content-visibility: visible !important;
}
```
The specific styling would surely need to be tailored to how the `amp-base-carousel` is configured.
The styling here is overriding these rules:
https://github.com/ampproject/amphtml/blob/bdfdcd0bd8ac47770982aefdddce4db0209bd942/css/ampshared.css#L284-L290
https://github.com/ampproject/amphtml/blob/bdfdcd0bd8ac47770982aefdddce4db0209bd942/css/ampshared.css#L269-L277
https://github.com/ampproject/amphtml/blob/bdfdcd0bd8ac47770982aefdddce4db0209bd942/css/ampshared.css#L304-L310
https://github.com/ampproject/amphtml/blob/bdfdcd0bd8ac47770982aefdddce4db0209bd942/css/ampshared.css#L284-L290
https://github.com/ampproject/amphtml/blob/bdfdcd0bd8ac47770982aefdddce4db0209bd942/extensions/amp-base-carousel/1.0/amp-base-carousel.css#L12-L17
Such SSR styling would likely apply to other similar components, including `amp-image-slider`.
### Alternatives Considered
n/a
### Additional Context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.