Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/GoogleChromeLabs/layout-shift-terminator


https://github.com/GoogleChromeLabs/layout-shift-terminator

cls cwv px

Last synced: 3 months ago
JSON representation

Awesome Lists containing this project

README

        

# Layout Shift Terminator

This tool aims to reduce [cumulative layout shift (CLS)](https://web.dev/cls/) for markup that lacks intrinsic sizing (and thus has visual instability). This issue is most often seen with social media embeds. In contrast with an image, iframe, or video which can (and should) be added with `width` and `height` attributes that correspond to the actual width and height of the content, this is often impossible for social media embeds with textual content that will have a variable height, especially considering the various screen sizes of the devices viewing the content.

Given a series of viewport dimensions for popular device form factors (e.g. mobile, tablet, desktop), this tool loads the markup into an `iframe` sized for each viewport. It waits for the page to load and then measures the size of the rendered markup for each viewport. Once these viewport-specific markup measurements are obtained, it then generates CSS [container queries](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Container_Queries) with the appropriate `min-height` for each viewport width. The original markup is wrapped with a `div` which includes this CSS as an inline `style` along with a `script` that will remove the `style` after a 4-second delay. This 4-second delay is intended to give the markup time to load before removing the `min-height` styles, which would not be needed anymore once the embed is loaded.

In short, this tool seeks to automate the process outlined for Embeds and iframes in [Optimize Cumulative Layout Shift](https://web.dev/optimize-cls/). It aims to improve [Core Web Vitals (CWV)](https://web.dev/vitals/) and thus enhance [page experience](https://developers.google.com/search/docs/appearance/page-experience).

In the end, a page which optimizes layout-unstable markup using this tool should have much less cumulative layout shift. This will make the page more likely to have a good [page experience](https://developers.google.com/search/docs/advanced/experience/page-experience).