• Resolved Vishal Lohar

    (@vlohar08)


    Hi,
    I am using the Astra theme with Woocommerce. Google Search Console is reporting CLS issues on all 300+ products for Mobile users. And the source of CLS is the product gallery. I tried checking the result without the Litespeed Optimization but nothing changed.

    I read multiple discussions on this topic but I was not able to find a proper solution.
    People are complaining for more than a year and there is no solution provided by Woocommerce yet.
    Please help!

    Please check this for your reference.
    I have compared the Product gallery HTML tag size during Initial loading and Final loading. And the difference is shocking. I wonder why this issue is not resolved by you guys.
    Initial Loading: https://ibb.co/YjPM9tC
    Final Loading: https://ibb.co/Ry4yQTP

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Support Kaushik S. a11n

    (@kaushiksomaiya)

    Hi there!

    Thank you for contacting us! πŸ™‚

    I understand you are having CLS issues on your site.

    The default WooCommerce Product gallery doesn’t introduce any CLS issue.

    For example, you can try testing this page on Google PageSpeed Insights: https://themes.woocommerce.com/storefront/product/woo-logo-2/

    Could you share the URL of your product page having this issue?

    The product gallery on your page may be getting controlled by your theme or another plugin. I’d suggest testing your product pages on a default theme like Storefront and seeing if the CLS issue disappears.

    I hope this helps!

    Thread Starter Vishal Lohar

    (@vlohar08)

    Hi, I have tested the storefront URL and my URL again. The content layout shift is happening on both the website and I have proof of that. I created a custom network speed of 100kbps in the developer console to test both the URLs.

    Check these two images:
    Storefront: https://ibb.co/YQ8SCZm
    Astra: https://ibb.co/kDVjDKx

    During the Initial load, the second image is placed right after the first image on both themes. The only difference is that In Astra the second image width is small. Because of this, the CLS issue is happening only on the product pages with more than one image. I have verified this in Google Search Console.

    Earlier I had a confusion that the second image is actually the gallery slider thumbnails but that’s not the case. The slider is not even loaded in the DOM during these tests.

    With the storefront theme, the change is happening fast, because of fewer plugins used and the default theme. All the tests were done with all optimization disabled.

    I am attaching a few product URLs, so you can test and provide a solution.
    https://expiry.link/0c5vm
    https://expiry.link/pcltu
    https://expiry.link/9c6dy
    https://expiry.link/lxezq

    Mirko P.

    (@rainfallnixfig)

    Hi @vlohar08,

    Thanks for the product URLs.

    I’ve performed a test with the first product “Alocasia Velvet Black Plant Sapling” and the Cumulative Layout Shift value needs improvement but it’s not too bad either.


    Image link: https://i.imgur.com/Jb1ioTL.png

    You would need to perform tests on your site’s product pages using Storefront and disabling all plugins except WooCommerce in an incognito Chrome browser window to get more genuine results. Nonetheless, this forum might be not the best place for insights on how to improve your CLS, and more likely your theme developers will be more familiar with this.

    Cheers.

    • This reply was modified 2 years, 5 months ago by Mirko P.. Reason: Edited image
    Thread Starter Vishal Lohar

    (@vlohar08)

    Okay, I actually contacted Astra before creating this thread. The Astra support advised me to contact Woocommerce as the gallery is added by Woocommerce.

    The gallery is not properly added during the initial load which results in CLS. I don’t know how I am going to fix it.

    Thank you for the help!

    Plugin Support Kaushik S. a11n

    (@kaushiksomaiya)

    Hi there @vlohar08

    I just tested some of your products on Google PageSpeed Insights, and I am seeing 0 CLS now, which is great.

    Could you confirm if you applied any fix? It would be great if you can share the solution here, it would be useful to other users. πŸ™‚

    Thread Starter Vishal Lohar

    (@vlohar08)

    Hi @kaushiksomaiya,
    Always test using the Developer Console Lighthouse tab. It will give a more detailed report and correct result. In page speed insights, the Image never loads, so CLS is always Zero.

    Anyway, I have applied a fix, and It’s not the best, but it worked for me.
    To fix this issue, I just used the max-height CSS property and added a custom CSS.

    Please remember this works for me and may not work for your theme.
    My solution works for websites with Square Images. Inspect the DOM to customize it for your theme.

    /*CSS for CLS Start*/
    /*For Desktop*/
    @media screen and (min-width: 922px) {
    	.woocommerce-product-gallery {
    	  min-height: 630px;
              max-height: 630px;
     }
    }
    /*For Mobile*/
    @media screen and (max-width: 921px) {
     .woocommerce-product-gallery > .flex-control-nav li {
    	height: calc(25vw - 1.5em) !important;
     }
    }
    @media screen and (max-width: 500px) {
    	.woocommerce-product-gallery {
    	max-height: calc((25vw - 1.5em) + (100vw - 56px) + 1em);
     }
    }
    @media screen and (min-width: 545px) and (max-width: 921px) {
    	.woocommerce-product-gallery {
    	max-height: calc((25vw - 1.5em) + (100vw - 117px) + 1em);
     }
    }
    /*CSS for CLS End*/

    Code Explanation
    For Desktop:
    I just added a min-height and max height to fix it. Inspect the DOM to find a perfect min and max height for the image gallery.

    For Mobile:
    I used only the max-height property.

    1. First set the gallery thumbnails size by using height: calc(25vw – 1.5em) !important;
    2. (25vw – 1.5ew) returns the height of slider thumbnails on different mobile screen sizes.
    3. (100vw – 117px) or (100vw – 56px) return the main image height minus the padding around it.
    4. 1em is the bottom margin of the main Image.
    5. Inspect the DOM to calculate the total padding around the main Image.
    6. Two media queries for mobile because the padding around is different below 500px and between 500px and 921px.

    Check this Image for visual representation: https://ibb.co/N2zVF4B
    I hope I was able to explain my solution. You can modify this code to make it more simple.

    Thread Starter Vishal Lohar

    (@vlohar08)

    The above solution may seem too much work for some people. WordPress is loved bcoz of its Simplicity and the Drag and Drop Interface.

    Therefore, A simple solution is to use a Gallery Plugin.
    Try this plugin –
    Additional Variation Images Gallery for WooCommerce

    This Gallery plugin will solve your CLS issue, irrespective of device and Image sizes.

    I would still advise Woocommerce to solve this issue in the Woocommerce plugin Itself. If another plugin can do it then why can’t Woocommerce?

    Hi @vlohar08

    Thanks for sharing your working solutions, code + plugin, with the community.

    I would still advise Woocommerce to solve this issue in the Woocommerce plugin Itself. If another plugin can do it then why can’t Woocommerce?

    With regards to improving WooCommerce default features, you can submit a request on our Ideas Board and add your vote(s) to it. The more popular an idea becomes, the more of a priority it is for our developers to review it. You can find the Ideas Board at: https://github.com/woocommerce/woocommerce/blob/trunk/.github/CONTRIBUTING.md#feature-requests-

    @vlohar08

    Your CSS worked for me. Thanks!

    /*CSS for CLS Start*/
    /*For Desktop*/
    @media screen and (min-width: 922px) {
    	.woocommerce-product-gallery {
    	  min-height: 630px;
              max-height: 630px;
     }
    }
    /*For Mobile*/
    @media screen and (max-width: 921px) {
     .woocommerce-product-gallery > .flex-control-nav li {
    	height: calc(25vw - 1.5em) !important;
     }
    }
    @media screen and (max-width: 500px) {
    	.woocommerce-product-gallery {
    	max-height: calc((25vw - 1.5em) + (100vw - 56px) + 1em);
     }
    }
    @media screen and (min-width: 545px) and (max-width: 921px) {
    	.woocommerce-product-gallery {
    	max-height: calc((25vw - 1.5em) + (100vw - 117px) + 1em);
     }
    }
    /*CSS for CLS End*/

    Vishal that is absolute gold!

    Hi Vishal,

    thanks for the help. This worked!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Cumulative Layout Shift (CLS) issue on Product Pages’ is closed to new replies.