• Hi,
    I wish to optimize my LCP. Google Lighthouse has identified my product images as causing the LCP to be >2.5
    Therefore I wish to preload them. What is the best approach to achieve this?
    All my non-product pages are good regarding Google Web Vitals.

    • This topic was modified 4 years, 9 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You could output a meta preload link to the image from the “wp_head” action. The crucial aspect would be obtaining the correct image URL from within the callback. The issue is this call happens outside the “Loop” so the usual template tag functions to get product images may not work. However, at least with single product pages, I believe the global $post variable is already assigned the current post/product object, so getting the right image URL should be feasible.

    Failing global $post being assigned, get_queried_object() ought to get the right post/product for single product requests. With the correct object, we can get its featured image URL with get_the_post_thumbnail_url(). I don’t know if that is the same as main product image or not. Use whatever function is needed, assuming it takes a post object or ID as a parameter. You can likely learn the correct function from the template code responsible for image output. Or ask though your e-commerce plugin’s support channel for suggestions.

    Thread Starter saens

    (@saens)

    Thanks! I’ll look into that.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Pre-load main product image only’ is closed to new replies.