FAQs

How can I avoid CLS (Cumulative Layout Shift)

FAQ 3 min read Intermediate

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.

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:

Display Configuration section of the bar campaign showing manual placement option

Accessing the Theme Code

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

  1. Online Store
Online Store navigation item in Shopify admin
  1. Click the ellipses drop-down (on the right side of the page):
Ellipses drop-down menu on the right side of the themes page
  1. Click ‘Edit Code
Edit Code option in the ellipses drop-down menu

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.
theme.liquid file inside the Layout folder in the code editor
  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.
Top of the page area in theme.liquid showing where to insert the code
  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:

Placeholder code with height styles pasted into theme.liquid for non-sticky placement
  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.
header.liquid file inside the Sections folder in the code editor
  1. Add some blank lines to the top of the file:
Blank lines added to the top of header.liquid
  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:

Placeholder code with height styles pasted at the top of header.liquid for sticky placement
  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.