Posts

Showing posts with the label skeleton screens

Optimizing CLS Score in NextJS

Image
Introduction In previous articles, I provided guidance on Core Web Vitals and how to optimize metrics such as LCP and INP. Now, we will continue to explore the final metric, which is CLS (Cumulative Layout Shift). Receiving data from multiple API requests at different times can easily cause sudden layout changes. Here are the solutions to address this: Explicit Dimensions : This involves declaring exact width and height for elements (especially images, videos and iframes) in HTML or CSS before they are downloaded. This helps the browser know the element size to build the layout beforehand. Without this, the browser will default to treating the element as 0px X 0px before assets are loaded. Once assets finish loading, they will suddenly expand in size, pushing surrounding content to different positions and c reating Layout Shift errors. Aspect Ratio: Instead of setting hard pixels, using Aspect Ratio is a modern solution to solve Explicit Dimensions by defining the ratio between the wi...