-
Notifications
You must be signed in to change notification settings - Fork 223
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
Preload LCP Hero Image #3626
Comments
I simply manually edited my header.php to preload my LCP image. That fixed it. The problem is you need to run an external benchmark program (PageSpeed) to determine the specific image that is the winning "LCP hero". Theoretically WP Rocket could make it easier by also saying you can preload images as well as fonts by entering the image URL in this section of WP Rocket: So future versions of WP Rocket can mention "You may also enter image URLs here too, but be sparing such as only LCP-impacting images, or performance may actually end up worse". (You don't want to preload too many images, but this can make it easier by not needing to manually edit header.php of your theme manually) |
Do you have the code used on the
I just need to pre-load the featured image/header image of each post as the other images in the post/s are lazyloaded and not visible on page load. |
(These instructions will help WP Rocket team figure out why image preload feature is useful) 1. Go to Google PageSpeed and benchmarkFigure out what image file it keeps complaining about:2. Go to Appearance -> Theme Editor3. Click Theme Header4. Edit the source(This only works if you have a common sitewide LCP image though like a background, not a per-page LCP image) 5. However, WP Rocket should make this easier for users ;)Because when upgrading stock themes, it will overwrite your change. So, it is an easy feature request for WP Rocket to let users specify which images to preload!
|
Thanks for the in-depth explanation. Unfortunately, your method works only if every page has the same header image. I was trying to have a dynamic PHP code that, given a certain post, detects which is the featured image and adds the preload image code on it. |
The following code should work. But I believe it could be improved further.
|
Thanks for the contribution! Google SEO is going to get worse soon (May 2021)https://www.searchenginejournal.com/largest-contentful-paint-lcp/374690/ Proposal: Changes to WP Rocket as follows:Because Google SEO is going to get worse beginning ~May 2021 if people don't fix their LCP statistics, it becomes necessary to preload certain images. It might potentially be an easy feature request for WP Rocket to let users specify which images to preload
(And obviously, ideally automatically select the WebP version instead of PNG/JPG if one exists, perhaps by a [X] Load WebP checkbox). cc: @GeekPress -- is this within scope of wp-rocket's mission? |
The code works very well. It could be a solution on WP Rocket |
Everything to improve PSI in our score ;) I'm going to close this request as we are currently trying to find a more general solution to preload critical images. |
One very big caveat, in my situation, @GeekPress -- is that my background image was in a CSS file. So it also ended up being a long critical chain too (HTML -> CSS -> image). You will have to worry about:
I had problems with both item 2 and 3. A universal situation doing all of 1/2/3 may be difficult -- I've seen PageSpeed squeal about LCP problems in all of these cases. Just some food for thought as you design a universal solution; |
@mdrejhon Thanks for the extra info. Indeed, we will try to cover all cases ;) |
Hey
|
Is your feature request related to a problem? Please describe.
Preload LCP Hero Image
Describe the solution you'd like
Load the hero image as
<link rel="preload" as="image" href="hero-image.jpg">
Additional context
It seems Google has changed something on the PageSpeed Insights and now it displays an error saying to preload the LCP hero image. Currently, the images are loaded via (I use jetpack CDN)
<img width="1920" height="1280" src="https://i1.wp.com/mysite/hero-image.jpg" class="flipboard-image wp-post-image lazyloaded" alt="image" sizes="(max-width: 1920px) 100vw, 1920px" srcset="//https://i1.wp.com/mysite/hero-image.jpg" data-ll-status="loaded">
The text was updated successfully, but these errors were encountered: