Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
westonruter opened this issue Sep 14, 2021 · 2 comments

Comments

@westonruter
Copy link
Member

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:

amp-base-carousel-ssr-styling.mov

The styling here applied is:

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:

amphtml/css/ampshared.css

Lines 284 to 290 in bdfdcd0

.i-amphtml-notbuilt:not(.i-amphtml-layout-container) > *,
[layout]:not([layout=container]):not(.i-amphtml-element) > *,
[width][height][sizes]:not([layout]):not(.i-amphtml-element) > *,
[width][height][heights]:not([layout]):not(.i-amphtml-element) > *
{
display: none;
}

amphtml/css/ampshared.css

Lines 269 to 277 in bdfdcd0

.i-amphtml-notbuilt,
[layout]:not(.i-amphtml-element),
[width][height][sizes]:not(img):not([layout]):not(.i-amphtml-element),
[width][height][heights]:not([layout]):not(.i-amphtml-element)
{
position: relative;
overflow: hidden !important;
color: transparent !important;
}

amphtml/css/ampshared.css

Lines 304 to 310 in bdfdcd0

.i-amphtml-notbuilt:not(.i-amphtml-layout-container),
[layout]:not([layout='container']):not(.i-amphtml-element),
[width][height][sizes]:not(img):not([layout]):not(.i-amphtml-element),
[width][height][heights]:not([layout]):not(.i-amphtml-element) {
color: transparent !important;
line-height: 0 !important;
}

amphtml/css/ampshared.css

Lines 284 to 290 in bdfdcd0

.i-amphtml-notbuilt:not(.i-amphtml-layout-container) > *,
[layout]:not([layout=container]):not(.i-amphtml-element) > *,
[width][height][sizes]:not([layout]):not(.i-amphtml-element) > *,
[width][height][heights]:not([layout]):not(.i-amphtml-element) > *
{
display: none;
}

/* Pre-upgrade: size-defining element - hide children. */
amp-base-carousel:not(.i-amphtml-built)
> :not([placeholder]):not([slot='i-amphtml-svc']) {
display: none;
content-visibility: hidden;
}

Such SSR styling would likely apply to other similar components, including amp-image-slider.

Alternatives Considered

n/a

Additional Context

No response

@samouri
Copy link
Member

samouri commented Feb 23, 2022

@westonruter: FYI, I recently added SSR capability to <amp-carousel> 0.1. Expanding to amp-base-carousel, and therefore 0.2 would also solve this (albeit it would be significantly more challenging to make the necessary buildDom than figuring out the correct CSS rules here)

@stale
Copy link

stale bot commented Mar 19, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Stale Inactive for one year or more label Mar 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants