- Joined
- Sep 3, 2014
- Messages
- 6,244
- Likes
- 13,130
- Degree
- 9
I'm considering using lazy loading since Google finally just released a new guide on how to make sure you do it in a way they can still crawl and index the images. The main thing they recommend in this secondary page is to use:
Pretty simple stuff. I then looked at some plugins to see how they were doing it. There's about 5 solid Lazy Load plugins and the rest seem shoddy. Of the main two, there's:
The first one uses jQuery.sonar and the plugin itself was made by Automattic (official Wordpress.com team), TechCrunch 2011 redesign team, and some guy called Jake Goldman. The second one was made by three guys I don't recognize. Both are being maintained it seems. This stuff doesn't break really unless Wordpress itself changes in some fundamental way.
My question is if you've used either of these plugins (recently is better) and are happy with them?
I like to avoid plugins where I can but will use one from a trusted team like Automattic who make money by keeping things updated.
Making one yourself is easy enough. You have to enqueue, for example, the IntersectionObserver API and Polyfill locally, then add an inline script in the footer or some other deferred javascript file you're already using. What this does is tell the main scripts (the API) to look for images with a certain CSS class attached like
From there, it'll take the
From there you can apply CSS to make the images fade in or whatever you want.
You can make this source swapping and CSS class adding happen in
So my next question is, in the case that the plugins above suck in some fashion, I need help with the Regex or whatever required to add a
- IntersectionObserver API
- Polyfill for the API above for older browsers
Pretty simple stuff. I then looked at some plugins to see how they were doing it. There's about 5 solid Lazy Load plugins and the rest seem shoddy. Of the main two, there's:
The first one uses jQuery.sonar and the plugin itself was made by Automattic (official Wordpress.com team), TechCrunch 2011 redesign team, and some guy called Jake Goldman. The second one was made by three guys I don't recognize. Both are being maintained it seems. This stuff doesn't break really unless Wordpress itself changes in some fundamental way.
My question is if you've used either of these plugins (recently is better) and are happy with them?
I like to avoid plugins where I can but will use one from a trusted team like Automattic who make money by keeping things updated.
Making one yourself is easy enough. You have to enqueue, for example, the IntersectionObserver API and Polyfill locally, then add an inline script in the footer or some other deferred javascript file you're already using. What this does is tell the main scripts (the API) to look for images with a certain CSS class attached like
.lazy-load
.From there, it'll take the
src="/path/to/image.jpg"
and move it to a srcset=
or data-src
to hold temporarily. Then it populates the original src=
with a placeholder image (which can be a 1x1 px image or some bigger one with your logo. When the image comes into view, it swaps the path to the image back to the src=
.From there you can apply CSS to make the images fade in or whatever you want.
You can make this source swapping and CSS class adding happen in
the_content();
and then you can manually add the CSS class to your theme files if you want, like images in the footer.So my next question is, in the case that the plugins above suck in some fashion, I need help with the Regex or whatever required to add a
<noscript>
catch for browsers and crawlers not using Javascript, because you'll need to go ahead and load the images instead of lazy loading them in that case. Could any of you help with that if the plugins suck? I'll share the main code minus that if that's the case.