-
-
Notifications
You must be signed in to change notification settings - Fork 888
Improved LCP by prioritizing the first image or carousel block #7791
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
base: main
Are you sure you want to change the base?
Improved LCP by prioritizing the first image or carousel block #7791
Conversation
| const blockType = block['@type']; | ||
| if (blockType === 'image' && block.url) { | ||
| return true; | ||
| } | ||
|
|
||
| if (blockType === 'listing' && block.variation === 'imageGallery') { | ||
| return true; | ||
| } | ||
|
|
||
| return false; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
5791643 to
2045892
Compare
| if (!block) return false; | ||
|
|
||
| const blockType = block['@type']; | ||
| const isEligible = config.settings.lcpEligibleBlocks[blockType]; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
Run the tests locally before committing.
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:Using that result, the rendering logic now:
loading="eager"+fetchpriority="high").Closes #7732