DevOps

Cumulative Layout Shift (CLS)

What is Cumulative Layout Shift (CLS)?

Cumulative Layout Shift (CLS) is a metric used to measure visual stability of a webpage. It quantifies how much unexpected layout shift occurs during the entire lifespan of a page. CLS is one of Google's Core Web Vitals and is important for user experience and SEO.

The Cumulative Layout Shift (CLS) is a vital metric in the field of DevOps, specifically in the realm of web performance optimization. This term refers to the unexpected shifting of web page elements while the page is still loading. In the context of DevOps, understanding and optimizing CLS is crucial for delivering a smooth and user-friendly web experience.

As part of the Core Web Vitals introduced by Google, CLS is a user-centric metric that quantifies how much a page's content visually shifts around. A low CLS helps ensure that the page is delightful to use and that its content is stable as it loads, thus contributing to a superior user experience.

Definition of Cumulative Layout Shift (CLS)

The Cumulative Layout Shift (CLS) measures the sum total of all individual layout shift scores for every unexpected layout shift that occurs during the entire lifespan of a page. A layout shift occurs any time a visible element changes its position from one rendered frame to the next.

CLS, as a metric, is dimensionless, as it is a representation of the impact of unstable content on the viewport area's percentage. The lower the CLS score, the better, with a score of 0 indicating no shifting, and higher scores indicating more significant shifting.

Calculating CLS

CLS is calculated by multiplying the impact fraction by the distance fraction. The impact fraction is the portion of the viewport that the unstable (moving) elements impact between two frames. The distance fraction is the greatest distance any element has moved, divided by the viewport's largest dimension.

It's important to note that CLS is a cumulative score for the entire lifespan of the page. It's not just about the initial page load; it also includes any shifts that happen as users interact with the page.

History of CLS

The concept of CLS was introduced by Google as part of its Core Web Vitals initiative, which was announced in May 2020. Core Web Vitals are a set of metrics designed to measure the speed, responsiveness, and visual stability of a webpage, with CLS specifically targeting visual stability.

Before the introduction of CLS, there was no standardized way to measure or quantify layout shifts. This made it difficult for developers to understand and improve their pages' visual stability. The introduction of CLS has provided a standardized, quantifiable way to measure and improve this aspect of user experience.

Core Web Vitals

Core Web Vitals are a set of real-world, user-centered metrics that quantify key aspects of the user experience. They measure dimensions of web usability such as load time, interactivity, and the stability of content as it loads, with CLS being the metric for the latter.

Google has stated that these vitals will be used as ranking signals in its search algorithm. This means that pages with a good CLS score could potentially rank higher in search results, making it an important metric for SEO as well as user experience.

Importance of CLS in DevOps

In the context of DevOps, CLS is a critical performance metric. DevOps is all about continuous delivery and integration, and part of that is ensuring that the end product (in this case, a web page) performs optimally. A low CLS score indicates that a page is stable and provides a good user experience, which is a key goal in DevOps.

Furthermore, since CLS is a Core Web Vital, it can impact a website's SEO performance. DevOps teams often work closely with SEO teams to ensure that the technical aspects of a website are optimized for search engines. Therefore, maintaining a low CLS score can be a critical part of a DevOps team's responsibilities.

Improving CLS

There are several strategies that DevOps teams can use to improve a page's CLS score. One of the most effective is to ensure that all elements on the page have a specified size. This prevents them from changing size or position as the page loads, which can cause layout shifts.

Another strategy is to limit the use of dynamically injected content, as this can often cause layout shifts. If dynamically injected content is necessary, it should be inserted below the current viewport, so it doesn't cause shifts in content that the user is currently viewing.

Use Cases of CLS

CLS is used in a variety of contexts, but its primary use is in web performance optimization. By monitoring and optimizing CLS, developers can create more stable, user-friendly web pages. This is particularly important for pages with complex layouts or dynamic content, as these are more likely to experience layout shifts.

CLS is also used in SEO, as it is one of the Core Web Vitals that Google uses as a ranking signal. By optimizing CLS, websites can potentially improve their search engine rankings, leading to more traffic and conversions.

CLS in E-commerce

In the e-commerce sector, a low CLS is crucial. Unexpected layout shifts can confuse or frustrate users, leading to a poor user experience and potentially lost sales. For example, if a user is about to click on a product and the layout shifts, causing them to click on a different product, they may become frustrated and leave the site.

Therefore, e-commerce sites often put a lot of effort into optimizing their CLS. This can involve techniques such as specifying sizes for images and videos, limiting the use of dynamically injected content, and using web fonts that don't cause layout shifts.

Examples of CLS

Let's consider a news website as an example. If the website has a high CLS score, it means that the elements on the webpage, such as images, advertisements, or text blocks, are likely to shift around as the page loads. This can be particularly frustrating for users who are trying to read an article, as the text can move around, making it difficult to follow.

On the other hand, a news website with a low CLS score will have a stable layout. The elements on the page won't shift around as the page loads, making it easier for users to read articles and interact with the site. This can lead to a better user experience, more time spent on the site, and more ad revenue for the site.

CLS in Mobile Web

CLS is particularly important in the context of mobile web. Mobile devices often have slower internet connections and smaller screens than desktop devices, which can make layout shifts even more disruptive. Therefore, optimizing CLS is particularly important for mobile web pages.

For example, a mobile news website with a high CLS score might have text blocks that shift around as images or ads load. This can make it difficult for users to read articles, leading to a poor user experience. On the other hand, a mobile news website with a low CLS score will have a stable layout, leading to a better user experience.

High-impact engineers ship 2x faster with Graph
Ready to join the revolution?
High-impact engineers ship 2x faster with Graph
Ready to join the revolution?

Do more code.

Join the waitlist