Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slick is blocking the main thread possibly causing worse Core Web Vitals scores for LCP and FID #2305

Open
Tiggerito opened this issue Jan 12, 2023 · 1 comment

Comments

@Tiggerito
Copy link
Contributor

I wrote an article on this, but think it would be worth baking a solution onto Cornerstone. It contains more details on the issue and solution:

I was doing a case study for a store related to getting them to pass their Core Web Vitals. In the process, I found that they sometimes had up to three slick sliders on a page, and they were blocking the main thread for a long time, causing a delay in rendering and stopping user interaction.

The relatively simple change splits the code up into multiple tasks, which lets other code, like the renderer, run in between them. I also built a way to delay the building of a slider (data-slick-delay) to further give time for more important code to run.

` // Let each carousel define its own delay
const delay = $carousel.data("slickDelay") || 0;

    setTimeout(() => {
        $carousel.slick({
            accessibility: false,
            arrows: isMultipleSlides,
            customPaging,
            dots: isMultipleSlides,
        });
    }, delay);  `
    data-slick-delay="2000"
    data-slick='{
        "arrows": {{arrows}},
        "mobileFirst": true,
        "slidesToShow": 1,
        "slidesToScroll": 1,
        "autoplay": true,
        "autoplaySpeed": {{carousel.swap_frequency}},
        "lazyLoad": "anticipated",
        "accessibility": false
    }'>```

It would require some decision-making on how long each slier should be delayed. e.g. any below the fold can have a long delay.

The sliders also need to be checked to ensure the pre-slider look matches the initial post-slider look.
@emilian
Copy link

emilian commented Jan 19, 2023

You could also try the approach of initializing the slick slider when the parent container is visible using IntersectionObserver.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants