Skip to content

Conversation

@Manik-Khajuria-5
Copy link
Contributor

@Manik-Khajuria-5 Manik-Khajuria-5 commented Jan 15, 2026

Issue

Contributes to #7732


PR DESCRIPTION

This PR introduces an LCP (Largest Contentful Paint) optimization mechanism for Volto when rendering pages that include image-heavy content.


Problem Addressed

Volto currently renders all image blocks with loading="lazy", including the first image on the page, which often becomes the LCP element.

What This PR Adds

I implemented a utility function getLCPBlockId(content) that inspects the blocks JSON and identifies:

  • the first Image Block, or
  • the first Listing block

Using that result, the rendering logic now:

  • Loads the first LCP candidate image eagerly (loading="eager" + fetchpriority="high").
  • If the first block is a carousel, only the first carousel image is eager; all others remain lazy to avoid regressions.


Closes #7732


@Manik-Khajuria-5 Manik-Khajuria-5 marked this pull request as ready for review January 15, 2026 10:22
Comment on lines 1002 to 1011
const blockType = block['@type'];
if (blockType === 'image' && block.url) {
return true;
}

if (blockType === 'listing' && block.variation === 'imageGallery') {
return true;
}

return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's best to keep this in configuration in config.settings so that add-ons can add blocks. For example:

    ....
    lcpEligibleBlocks: {
      image: (block) => !!block.url,
      listing: (block) => block.variation === 'imageGallery',
    },

See: https://github.com/plone/volto/blob/main/packages/volto/src/config/index.js#L60

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several other blocks can contain images, such as LeadImage, Teaser, and Video. Even the Slate block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, sure I’ll make these changes as soon as possible

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have made required changes. Can u please review it again @wesleybl

@Manik-Khajuria-5 Manik-Khajuria-5 force-pushed the fix-lcp-eager-image-latest branch from 5791643 to 2045892 Compare January 29, 2026 09:14
@Manik-Khajuria-5 Manik-Khajuria-5 marked this pull request as draft January 29, 2026 11:53
@Manik-Khajuria-5 Manik-Khajuria-5 marked this pull request as ready for review January 29, 2026 12:33
if (!block) return false;

const blockType = block['@type'];
const isEligible = config.settings.lcpEligibleBlocks[blockType];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try doing this:

import '@plone/volto/config';

In the tests that resulted in errors, this will ensure the config file is populated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve made the suggested changes and tested everything locally again. At the moment, there are no failing tests on my end @wesleybl

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it looks like this won't work. You can undo what you did. You'll have to fill in the configuration in the tests yourself. See:

https://github.com/plone/volto/blob/main/packages/volto/src/components/theme/Navigation/Navigation.test.jsx#L12-L15

Run the tests locally before committing.

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.

Improve LCP by prioritizing the first image or carousel block

2 participants