wp-rocket icon indicating copy to clipboard operation
wp-rocket copied to clipboard

Lazyload not working properly on Safari/Chrome 15.4 if loading=lazy is present on the image

Open DahmaniAdame opened this issue 2 years ago • 14 comments

Before submitting an issue please check that you’ve completed the following steps:

  • [x] Made sure you’re on the latest version
  • [x] Used the search feature to ensure that the bug hasn’t been reported before

Describe the bug Lazyload will fail on the first couple of images on the page if they somehow contain loading="lazy" when using iOS 15.4 Safari/Chrome.

Video comparing behavior on 15.4 vs. 15.3.

https://drive.google.com/file/d/11i0xxEKciie7HpvWc0EiYCx28aPKHfrP/view?usp=drivesdk

The initial load works properly. When the page is re-visited, the first images are not lazyloaded.

There is no console error. And the image swapped.

15.4 added support to native lazyload.

https://developer.apple.com/documentation/safari-release-notes/safari-15_4-release-notes

Since Chrome for iOS 15.4 is also affected by the issue, then the change is likely done on WebKit, since Chrome for iOS is forced to use it.

Since it's the main difference between 15.4 vs. 15.3, it is likely what is causing the behavior.

Removing loading=lazy on lazyloaded images fixed the issue on 5 different websites.

We could sanitize lazyloaded images to make sure they don't include loading="lazy" at the same time.

https://github.com/wp-media/wp-rocket/blob/6f905396f43c1831c370848e9c36bf14e72ab545/inc/Dependencies/RocketLazyload/Image.php#L454-L469

To Reproduce Steps to reproduce the behavior:

  1. Use iOS 15.4 Safari or Chrome
  2. Enable lazyload
  3. Make sure that the loading="lazy" is added to the image after it's processed
  4. See error

Expected behavior Lazyload should work properly on all Safari browsers.

Screenshots N/A

Additional context Tickets:

  • https://secure.helpscout.net/conversation/1846557294/337237
  • https://secure.helpscout.net/conversation/1854681070/338402
  • https://secure.helpscout.net/conversation/1821189163/332608

Backlog Grooming (for WP Media dev team use only)

  • [ ] Reproduce the problem
  • [ ] Identify the root cause
  • [ ] Scope a solution
  • [ ] Estimate the effort

DahmaniAdame avatar Apr 23 '22 07:04 DahmaniAdame

Related - https://secure.helpscout.net/conversation/1858594675/338974/

DahmaniAdame avatar Apr 23 '22 09:04 DahmaniAdame

maybe related https://secure.helpscout.net/conversation/1859522245/339096

worldwildweb avatar Apr 26 '22 06:04 worldwildweb

Related - https://secure.helpscout.net/conversation/1858594675/338974 Temporarily fixed by removing loading=lazy using manipulate buffer helper plugin.

DahmaniAdame avatar Apr 29 '22 09:04 DahmaniAdame

Related - https://secure.helpscout.net/conversation/1892367990/344316/ Temporarily fixed by removing loading=lazy using manipulate buffer helper plugin.

DahmaniAdame avatar May 24 '22 06:05 DahmaniAdame

related: https://secure.helpscout.net/conversation/1896784059/344970

worldwildweb avatar May 25 '22 14:05 worldwildweb

related: https://secure.helpscout.net/conversation/1915957845/347723?folderId=2683093

alfonso100 avatar Jun 10 '22 12:06 alfonso100

Related - https://secure.helpscout.net/conversation/1913205820/347217/

Temporarily fixed by removing loading=lazy using manipulate buffer helper plugin.

DahmaniAdame avatar Jun 11 '22 04:06 DahmaniAdame

is it possible to share the plugin/function being used to strip the loading=lazy? We're having this issue with a client site (http://influitive.com/) and trying to figure out how to resolve. We have an active WP Rocket account but can't log in as the password reset links are going to a 503 page - otherwise I would have submitted a ticket normally (account email [email protected]).

JoshuaVB avatar Jun 15 '22 01:06 JoshuaVB

@JoshuaVB WP Rocket customer service linked me this plugin https://jmp.sh/AEmEIZD

It worked, but i've since then decided to disable lazy-loading via WP rocket since Wordpress has implemented native lazy loading since WP 5.5, so I decided to just use that.

melissahie avatar Jun 15 '22 02:06 melissahie

@JoshuaVB the helper plugin @melissahie shared is the one.

@melissahie a quick clarification about the native lazyload.

It has a 1250px (up to 2500px on 3G) threshold from the viewport vs. our lazyload has a 300px threshold from the viewport.

That means the native lazyload will trigger loading images way too early, and in some cases, it will load unnecessary images that the user won't reach on their visit.

Native lazyload is a scriptless solution to lazyload images. They already did an effort in dropping the threshold from 4000px to 1250px. But it's not the best performance gain possible regarding deferring images load :)

DahmaniAdame avatar Jun 15 '22 07:06 DahmaniAdame

@DahmaniAdame thanks for the detailed explanation. it's what i was trying to find out when I was deciding between native vs WP rocket lazy load! I'll take a look again and see which one is best for my website.

melissahie avatar Jun 15 '22 07:06 melissahie

@melissahie @DahmaniAdame Thanks for providing the plugin! It worked perfectly simply by adding to the site, a very tidy fix. We use Divi and so presuming that was the culprit.

I agree with @DahmaniAdame that Native lazyload threshold is too high, it may be that they really want to give the browser enough time to load the image before you reach it on slow networks. Either way, it triggers too many "below the fold" errors for us to use it in production, so this is a great fix - thank you!

JoshuaVB avatar Jun 18 '22 22:06 JoshuaVB

related: https://secure.helpscout.net/conversation/1932257775/350794

worldwildweb avatar Jun 29 '22 08:06 worldwildweb

Related https://secure.helpscout.net/conversation/1940750121/354049/

juricazuanovic avatar Jul 21 '22 14:07 juricazuanovic

Hello, do we know on which version this fix will be released? I want to uninstall the hotfix plugin once this fix has been released.

melissahie avatar Sep 06 '22 02:09 melissahie

Hello @melissahie It'll be added to 3.12.1 version of the plugin.

piotrbak avatar Sep 06 '22 09:09 piotrbak