Skip to content

St/responsive images dpr lcp#66

Open
Rivka-Development wants to merge 16 commits intoShopify:mainfrom
Rivka-Development:ST/responsive-images-DPR-LCP
Open

St/responsive images dpr lcp#66
Rivka-Development wants to merge 16 commits intoShopify:mainfrom
Rivka-Development:ST/responsive-images-DPR-LCP

Conversation

@Rivka-Development
Copy link

Optimizations implemented to improve the LCP (Largest Contentful Paint) and overall mobile performance of the Shopify theme.

1. Responsive Images & LCP Optimization (Phase 1)
I enhanced the image loading strategy to ensure critical assets load as fast as possible while secondary images are deferred.

Key Changes:
snippets/image.liquid: Expanded widths to include intermediate candidates (535, 750, 1070) for better DPR coverage.
Implemented a robust sizes attribute calculation based on layout requirements.
Integrated fetchpriority and loading attributes directly into the image_tag.
**sections/hero.liquid & sections/_layered-slide.liquid:**
Identified as potential LCP candidates.
Applied loading="eager" and fetchpriority="high" to the first image found in these sections.
layout/theme.liquid:Added a conditional preload for the first LCP image (Hero or Slideshow) to start downloading it immediately.

2. Deferred Hydration for Mobile (Phase 2)
To reduce the main thread work and improve TBT (Total Blocking Time) on mobile, I implemented a deferred hydration utility.

Key Changes:

**assets/deferred-hydration.js:** Created a custom element that uses IntersectionObserver to only render its content when it enters the viewport (or is about to, with a 200px margin).
Includes a data-mobile-only attribute to ensure desktop users get the full experience immediately while mobile users benefit from lazy loading heavy sections.

Wrapping Heavy Sections:
blocks/accordion.liquid: Wrapped content to defer accordion initialization.
blocks/review.liquid: Wrapped review stars to defer third-party or heavy rendering.
blocks/product-recommendations.liquid: Wrapped the entire recommendations section, which is typically heavy and below the fold.

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

Successfully merging this pull request may close these issues.

1 participant