ampproject / ampproject/amphtml

Add SSR styling to reduce LCP for `amp-base-carousel` by showing first slide at first paint

Aperta
#36,070 2 commenti 4 reazioni 0 assegnatari Vedi su GitHub
Stale Type: Feature Request WG: bento WG: performance
Lingua principale
JavaScript
Stelle
14.9k
Fork
4.1k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

### 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_

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Leggi le regole referenziate in css/ampshared.css e extensions/amp-base-carousel/1.0/amp-base-carousel.css, quindi confrontale con l'esempio collegato. Determina come dovrebbe variare lo stile in base alla configurazione di amp-base-carousel e verifica che la diapositiva iniziale sia visibile prima che l'elemento venga creato, anche quando JavaScript è disabilitato o lo script non riesce.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
css, javascript
Ambito
frontend, performance
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.