How can I avoid CLS (Cumulative Layout Shift)

You may have noticed that when the Free Shipping Bar loads, it causes the page to shift down slightly to accommodate the space it needs to display.

The reason for this is due to the design Shopify has chosen to load pages. First, the core Shopify content loads, after that, the apps are loaded in the order they were installed. So it's only after the page has loaded that the Free Shipping bar is inserted, causing the layout shift. 


If you are looking to avoid this shift, a possible solution is to insert the bar manually into your theme and include styling code to make space for the bar's contents.

Given that themes are all designed a little differently, it's difficult to create a step-by-step guide for all themes, but hopefully this guide for Dawn can get you pretty close.


NOTE:

This is a general guide and may not apply to all themes. It is provided as a tool for merchants and their developers to overcome CLS issues.


Before we begin......

Ensure that the bar is set to manual placement.

This can be found in the Display Configuration part of the bar campaign:



Accessing the Theme Code

To begin, you'll need to get into the code editing space. Click on: 

  1. Online Store


  1. Click the ellipses drop-down (on the right side of the page):



  1. Click 'Edit Code'


From here, you can choose if you prefer the bar to scroll with the page or not.

Note that both options set up the theme to create a space that the bar will fill when it's loaded. If the bar is a little bigger or smaller, the space will adjust. You can edit the sizes from 33.5 or 44 to whatever value that fits the bar that you've designed. 33.5 is for mobile view and 44 is for desktop.


Keep the bar at the top (non-scrolling / non-sticky):


  1. Click on theme.liquid found inside the Layout folder.


  1. From here, you need to find the top of the page. A line above the header or the announcement bar is usually a good place to begin.

Screen_Shot_2022-09-23_at_4.30.55_PM.png


  1. In that area, paste this code:


<div id="fsb_placeholder">&nbsp;</div> 
<style>
@media only screen and (max-width: 768px) {
#fsb_placeholder{
height: 33.5px;
}
}
@media only screen and (min-width: 769px){
#fsb_placeholder{
height: 44px;
}
}
</style>

Like so:


  1. Save the changes to the theme and preview it to see how it looks.

Keep the bar at the top (scrolling / sticky):

  1. Inside the Sections folder you'll find the file header.liquid. Open that file.

Screen_Shot_2022-09-23_at_5.03.40_PM.png


  1. Add some blank lines to the top of the file:

Screen_Shot_2022-09-23_at_5.04.44_PM.png


  1. Then at the very top, paste in this code:

<div id="fsb_placeholder">&nbsp;</div> 
<style>
@media only screen and (max-width: 768px) {
#fsb_placeholder{
height: 33.5px;
}
}
@media only screen and (min-width: 769px){
#fsb_placeholder{
height: 44px;
}
}
</style>

Like so:


  1. Save the changes to the theme and preview it to see how it looks.

Please feel free to reach out at help@hextom.com if you have any further questions or concerns.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us