Skip to content

fix(perf): eager-load the first LCP-candidate card image - #655

Closed
sdmcraft wants to merge 2 commits into
mainfrom
cwvfix
Closed

fix(perf): eager-load the first LCP-candidate card image#655
sdmcraft wants to merge 2 commits into
mainfrom
cwvfix

Conversation

@sdmcraft

Copy link
Copy Markdown
Contributor

Summary

Fixes #518: blog-cards.js, related-blogs.js, blog-rail-case-study.js, and event-cards.js all hardcoded loading="lazy"/eager=false for every card image regardless of position — including the first card, which is the LCP candidate on the 16+ category/author/listing pages this issue identified (and /blog itself, which I confirmed has the same pattern — see comment on #518).

Fix

Only the first card of the first instance of each block on a page now loads eagerly. This matters because several templates stack multiple instances of the same block on one page:

  • /blog has 5 separate blog-cards sections
  • /events has 2 event-cards grids (.upcoming, .on-demand)

Marking every instance's first card eager (the issue's literally-suggested fix) would eager-load one image per section — wasting bandwidth/priority on below-the-fold images and potentially delaying the actual LCP image. Instead, decorate() checks document.querySelector('.block-name') === block once, synchronously, before any async work — this is safe because EDS delivers all section/block markup in the initial HTML; only JS decoration is staged, so every block instance already exists in the DOM by the time any of them starts decorating.

related-blogs.js/blog-rail-case-study.js aren't wired into any live content yet (confirmed via git history and content search), but had the identical hardcoded-lazy pattern per the issue's audit checklist — fixed for consistency/future-proofing.

Verified

  • Traced the exact LCP element the issue cited (construction-study.jpg on /blog/guide) — confirmed via performance trace it's the same node, now loading="eager" with "Load duration" collapsing from ~1.2s to ~6ms (image no longer discovered late).
  • Checked /blog (5 instances) and /events (2 instances) directly in-browser: exactly 1 eager image total on each page, matching the true first/LCP-position card.
  • No CSS order/reordering — DOM order matches visual order, so i === 0 is reliably the visually-first card.
  • Added test coverage (test/event-cards.test.js) for the isFirstOnPage behavior — the existing decorate() tests never attached blocks to document.body, so this logic was previously unexercised by the suite.
  • npm run lint clean; npx vitest run — same 11 pre-existing failures as main (comparison-table, lead-form-config, testimonial-video/-split), unrelated to these files, no regressions.

Preview

https://cwvfix--intuit-erp--aemsites.aem.page/blog/guide

Fixes #518

Satya Deep Maheshwari added 2 commits August 18, 2026 10:39
blog-cards.js, related-blogs.js, blog-rail-case-study.js, and event-cards.js
all hardcoded loading="lazy"/eager=false for every card image regardless of
position, deferring even the first card's image past first paint on
category/author/listing pages where it's the LCP candidate.

Only the first card of the first instance of each block on a page now loads
eagerly - pages with multiple stacked instances (e.g. /blog's 5 blog-cards
sections, /events' two event-cards grids) would otherwise eager-load one
image per instance, wasting bandwidth/priority on below-the-fold images.

Fixes #518
The existing decorate() tests never attach blocks to document.body, so the
new isFirstOnPage check (document.querySelector(...) === block) was
previously unexercised by the test suite.
@aem-code-sync

aem-code-sync Bot commented Aug 18, 2026

Copy link
Copy Markdown

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch and validate page speed.
In case there are problems, just click a checkbox below to rerun the respective action.

  • Re-run all PSI checks
  • Re-run failed PSI checks
  • Re-sync branch
Commits

@aem-code-sync

aem-code-sync Bot commented Aug 18, 2026

Copy link
Copy Markdown
Page Scores Audits
📱 /blog/guide PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS
🖥️ /blog/guide PERFORMANCE A11Y SEO BEST PRACTICES SI FCP LCP TBT CLS

@usman-khalid
usman-khalid force-pushed the main branch 2 times, most recently from 40a49bf to 0a53fdd Compare August 19, 2026 18:21
@sdmcraft sdmcraft closed this Aug 25, 2026
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.

CWV Issues : LCP Regression on Blog Listing / Category / Author Pages

1 participant