jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Lazy Load: Images not lazy loading within Related Posts

Open ntpixels opened this issue 7 years ago • 13 comments

Summary A user reached out after noticing that Jetpack's lazyload classes aren't being applied to their related posts sections. After testing this on our own sites, we are experiencing the same: lazyload is being applied to images in the post body (single images, galleries), but not to related post images.

Steps to Reproduce

  1. Enable Jetpack's Lazy Load functionality
  2. Enable Jetpack's Related Posts, and related post feature image, functionality
  3. Activate a default theme, like Twenty Nineteen
  4. Inspect the related post featured images. They are missing the jetpack-lazy-image and jetpack-lazy-image--handled classes.

JP v 7.5.2:

JP v 7.1.1: Screen Shot 2019-07-16 at 12 22 49 PM

Tested with

  • All plugins except Jetpack, Akismet, and VaultPress disabled
  • Jetpack v 7.1.1 and v 7.5.2
  • Default themes: Twenty Nineteen and Seventeen
  • Reinstalling and reconnecting Jetpack
  • Toggling the relevant Jetpack settings
  • Confirmed that there are no console errors
  • This works fine with the OceanWP theme, although we suspect that it's using its own Related Posts markup.

ntpixels avatar Jul 16 '19 19:07 ntpixels

I am experiencing the same issue. Additionally the problem appears for lists of posts and main page (which in my case is basically a list of posts) - there is no lazy loading for images besides the ones inside particular post.

Examples: https://karieranaobcasach.com https://karieranaobcasach.com/category/project-management/ https://karieranaobcasach.com/2016/04/design-thinking/ ("you might also like" section)

rsamborski avatar Aug 06 '19 22:08 rsamborski

I'm also experiencing this issue where images within the Jetpack related posts module are not being lazy-loaded.

Is there any update to this?

A possible solution would be to lazy load the entire module rather than just the images.

benjamin-t-gray avatar Nov 12 '19 14:11 benjamin-t-gray

Is there any update to this?

Not yet, but we'll update this issue once we make progress on this.

jeherve avatar Nov 12 '19 15:11 jeherve

I'm having the same issue with Autoptimize's lazyload. I open a thread on Autoptimize's support forum and after a discussion, I realized that Jetpack uses JS to insert the related posts into the DOM dynamically.

Is there any workaround to make it statically? So Lazyload plugins can filter the output?

rilwis avatar Dec 27 '19 01:12 rilwis

Is there any workaround to make it statically? So Lazyload plugins can filter the output?

Yes, you can use this method to output your own Related Posts, using the index of posts prepared by Jetpack: https://jetpack.com/support/related-posts/customize-related-posts/#raw

jeherve avatar Jan 06 '20 15:01 jeherve

As this is still open, could we then at lead get loading="lazy" implemented That way at least all supporting browses would handle this for you. https://caniuse.com/#feat=loading-lazy-attr

I'd guess it should be added around here: https://github.com/Automattic/jetpack/blob/771f691a72715db3e8c5de604d3b94b86cdb3509/modules/related-posts/related-posts.js#L157

Squazz avatar Mar 15 '20 11:03 Squazz

could we then at lead get loading="lazy" implemented

Noting that this feature will be added to WordPress itself in version 5.5: https://make.wordpress.org/core/2020/02/25/lazy-loading-update/

Jetpack will consequently be updated accordingly.

jeherve avatar Mar 16 '20 08:03 jeherve

This issue has been marked as stale. This happened because:

  • It has been inactive in the past 6 months.
  • It hasn’t been labeled `[Pri] Blocker`, `[Pri] High`.

No further action is needed. But it's worth checking if this ticket has clear reproduction steps and it is still reproducible. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation.

stale[bot] avatar Sep 12 '20 10:09 stale[bot]

Even after WordPress latest update, it is still hard to get lazy load on jetpack related posts images...

samafroxy22 avatar Jan 19 '21 08:01 samafroxy22

@jeherve Since it's safe to assume that lazy loading is OK for related post images, and WordPress isn't handling images that are dynamically loaded via scripts, is it too much to ask that you add loading="lazy" to the IMG tags in the script?

These images are the ONLY ones that Google PageSpeed lists as not being deferred on my sites, as, I would imagine, on many other well optimised sites, and it's such a small effort with no down side.

galbaras avatar Sep 14 '21 02:09 galbaras

is it too much to ask that you add loading="lazy" to the IMG tags in the script?

That's what we were discussing above indeed. I just opened #21073 for it.

jeherve avatar Sep 14 '21 12:09 jeherve

Awesome. I hope this will be released soon.

Yes, you can use this method to output your own Related Posts, using the index of posts prepared by Jetpack: https://jetpack.com/support/related-posts/customize-related-posts/#raw

I've activated Jetpack on a test site that uses the Classic Editor plugin and Classic Widgets, in case this makes a difference. It took me a while to figure out how to get all the attributes (url, image, etc), to output them in the same structure as the script does and to disable the script, so that snippet is very partial.

Also, is there any difference between the static/PHP related posts and the ones output by the script?

galbaras avatar Sep 15 '21 03:09 galbaras

is there any difference between the static/PHP related posts and the ones output by the script?

No, there shouldn't be. Both pull the related posts from the same index on WordPress.com.

jeherve avatar Sep 15 '21 10:09 jeherve