Hi there,
Awesome plugin! Only one I’ve managed to get to work on Woocommerce product thumbnails with my set up ??
I was wondering if there’s an option for a placeholder / space filler on mobile at all?
Here’s an example of what I mean: Marvel Comics
You should see that regardless of how quickly you scroll down on desktop the lettering is evenly spaced under where the thumbnail images will appear, whereas on mobile the the titles are bunched up until the images load.
And help would be very much appreciated!
Kind regards,
JP
Hello!
I noticed a site using your plugin had issues with not loading images. It seemed to be that the scroll was not detected because the page had a slideshow format that did not trigger the window.scroll() event. For example, here.
A possible fix for this could be replacing:
window.scroll(function(){
with
$(window).on("scroll wheel", function () {
You also might want to check out the window.scroll() optimization here.
If you like both of those ideas, here is an updated version of your JS file:
/*
Plugin Name: Zedna WP Image Lazy Load
Plugin URI: https://profiles.www.ads-software.com/zedna#content-plugins
Text Domain: wp-image-lazy-load
Domain Path: /languages
Description: Image lazy load plugin to boost page load time and save bandwidth by removing all the images, background-images, responsive images, iframes and videos. Elements will load just when reach visible part of screen. Lazy loading can be also applied on themes.
Version: 1.6.3.3
Author: Radek Mezulanik
Author URI: https://cz.linkedin.com/in/radekmezulanik
License: GPL3
*/
(function ($) {
//get options from DB
var skipIframe = wpimagelazyload_settings.wpimagelazyloadsetting_skipiframe; //true=skip iframe, false=apply the code
var skipParent = wpimagelazyload_settings.wpimagelazyloadsetting_skipparent;
var skipAllParent = wpimagelazyload_settings.wpimagelazyloadsetting_skipallparent.split(";");
var skipVideo = wpimagelazyload_settings.wpimagelazyloadsetting_skipvideo;
var loadonposition = parseInt(wpimagelazyload_settings.wpimagelazyloadsetting_loadonposition);
var importantVC = wpimagelazyload_settings.wpimagelazyloadsetting_importantvc;
//Check if element has some class that should be skipped
function myClasses(element, skipClasses) {
if (skipAllParent.length > 0 && $(element).parents().hasClass(skipAllParent)) {
return false;
}
if (element instanceof SVGElement === false) {
var myClasses = element.className.split(' ');
if (myClasses.some(function (v) { return skipClasses.indexOf(v) >= 0; })) {
return false;
} else {
return true;
}
}
}
$('document').ready(function () {
//set visible part of screen
var scrollBottom = $(window).scrollTop() + window.innerHeight;
/*
-remove & backup source from images
-remove & backup source set from responsive images
-give back source of visible images
-for some browsers, <code>bgbak</code> is undefined; for others, <code>bgbak</code> is false -> check both like: if (typeof srcsetbak !== typeof undefined && srcsetbak !== false)
*/
$('img').each(function () {
console.log("image");
if (myClasses(this, skipAllParent)) {
this.setAttribute('src-backup', this.src);
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
var srcsetbak = $(this).attr('srcset');
if (srcsetbak) {
$(this).attr("srcset-backup", srcsetbak);
}
if (scrollBottom < isvisible) {
this.style.opacity = "0";
this.setAttribute('src', '');
this.setAttribute('srcset', '');
}
}
});
/*
remove & backup source from videos
give back source of visible videos
*/
if (skipVideo === "false") {
$('video').each(function () {
if (myClasses(this, skipAllParent)) {
this.setAttribute('src-backup', this.src);
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
var source = elements.find("source");
if (scrollBottom < isvisible) {
this.style.opacity = "0";
this.setAttribute('src', '');
for (i = 0; i < source.length; i++) {
source[i].setAttribute('src-backup', source[i].src);
source[i].setAttribute('src', '');
}
}
}
});
}
/*
remove & backup source from iframes
give back source of visible iframes
*/
if (skipIframe === "false") {
$('iframe').each(function () {
if (myClasses(this, skipParent)) {
this.setAttribute('src-backup', this.src);
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
if (skipParent.length !== 0) {
//skip this iframe
} else {
if (scrollBottom < isvisible) {
this.setAttribute('src', '');
this.style.opacity = "0";
} else {
this.style.opacity = "1";
}
}
}
});
}
$("*").each(function () {
if (myClasses(this, skipAllParent)) {
//remove & backup background-image from all elements
if ($(this).css('background-image').indexOf('url') > -1) {
var bg = $(this).css('background-image');
$(this).attr("background-image-backup", bg);
if (importantVC) {
$(this).css('cssText', 'background-image: none !important');
} else {
$(this).css('background-image', 'none');
}
}
//give back background-image of all visible elements
var bgbak = $(this).attr("background-image-backup");
if (bgbak) {
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
if (scrollBottom >= isvisible) {
if (importantVC) {
$(this).css('cssText', "background-image: " + bgbak + " !important");
} else {
$(this).css("background-image", bgbak);
}
}
}
}
});
});
var scrolling = false;
//Detect if user scrolled to the image
$(window).on("scroll wheel", function () {
scrolling = true;
});
setInterval( function() {
if ( scrolling ) {
scrolling = false;
// Do your thang!
//set visible part of screen
var scrollBottom = $(window).scrollTop() + window.innerHeight;
//give back source of visible images
$('img').each(function () {
if (myClasses(this, skipAllParent)) {
var isLoaded = $(this).attr("src");
var isLoaded2 = $(this).attr("srcset");
var hasBackup = $(this).attr("srcset-backup");
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
if (scrollBottom >= isvisible) {
if (!isLoaded) { //check if source is not set
this.src = this.getAttribute('src-backup');
this.className += " fadein";
this.style.opacity = "1";
}
if (!isLoaded2) { //check if source is not set
if (hasBackup) {
$(this).attr("srcset", hasBackup);
}
}
}
}
});
//give back source of visible videos
if (skipVideo === "false") {
$('video').each(function () {
if (myClasses(this, skipAllParent)) {
var isLoaded = $(this).attr("src");
var isLoaded2 = $(this).attr("srcset");
var hasBackup = $(this).attr("srcset-backup");
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
var source = elements.find("source");
if (scrollBottom >= isvisible) {
if (!isLoaded) { //check if source is not set
this.src = this.getAttribute('src-backup');
if (this.classList.contains("fadein") === false) {
this.className += " fadein";
}
this.style.opacity = "1";
for (i = 0; i < source.length; i++) {
source[i].src = source[i].getAttribute('src-backup');
}
}
if (!isLoaded2) { //check if source is not set
if (hasBackup) {
$(this).attr("srcset", hasBackup);
}
}
}
}
});
}
//give back source of visible iframes
if (skipIframe === "false") {
$('iframe').each(function () {
if (myClasses(this, skipParent)) {
var isLoaded = $(this).attr("src");
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
var hasBackup = $(this).attr("src-backup"); //check if iframe has backup source
var found;
if (skipParent.length !== 0) {
found = $(this).parents().hasClass(skipParent); //look for ignored parent
}
if (scrollBottom >= isvisible) {
if (!isLoaded) { //check if source is not set
if (found && skipParent.length !== 0) {
//ignored parent was found, so leave it as it is
} else {
this.src = this.getAttribute('src-backup');
this.className += " fadein";
this.style.opacity = "1";
}
}
}
}
});
}
//give back background-image of all visible elements
$("*").each(function () {
if (myClasses(this, skipAllParent)) {
var bgbak = $(this).attr("background-image-backup");
if (bgbak) {
var elements = $(this);
var elementsoffset = elements.offset();
var isvisibleOriginal = parseInt(elementsoffset.top);
var isvisible = isvisibleOriginal + loadonposition;
if (scrollBottom >= isvisible) {
if ($(this).css('background-image').indexOf('url') === -1) { //check if source is not set
if (importantVC) {
$(this).css('cssText', "background-image: " + bgbak + " !important");
} else {
$(this).css("background-image", bgbak);
}
}
}
}
}
});
}
});
})(jQuery);
Thanks for the great plugin, cheers.
]]>After the update a section that relied on skipping lazy load via class on the parent now breaks (lays out incorrectly) and I think I know why.
Specifically logic equivalent of this:
if (skipAllParent.length > 0 && $this.parents().hasClass(skipAllParent) ) {
// skip
}
has been replaced by this:
//Check if element has some class that should be skipped
function myClasses(image, skipClasses) {
if (image instanceof SVGElement === false) {
var myClasses = image.className.split(' ');
if (myClasses.some(function (v) { return skipClasses.indexOf(v) >= 0; })) {
return false; // skip
} else {
return true; // lazyload
}
}
}
which you’ll note checks only the className of image
– not its parents – which it should (given the name skipAllParents).
Hello, Images are not display when printing pages. Can I turn off the plugin to print pages?
The plug-in is great, but I need to create a printing-friendly website.
It′s weird now it works only if i fill the “skip” fields with some word (with class that actually does not exist). I′ve tested it many times. If i leave them blank, it doesn′t work.
?Do somebody have this issue?
Of course it′s solved for me, i found a solution
]]>Background images are not lazy loaded anymore…
Version 1.6.3 => It doesn’t work
Version 1.6.2.2 => It’s OK
I have seen you told on a recent topic “this has been fixed in latest release.”
But 1.6.3 is the latest release, right ?
Thank you for your help.
]]>It stopped working in my site, it only works with posts of blog, category and archive pages but not with static pages and widgets (all of them with css background images).
]]>It stopped working in my site, it only works with posts of blog, category and archive pages but not with static pages and widgets (all of them with css background images).
]]>I saw this mentioned in another thread but thought I would offer more information. The way the lazy loading technique works for background images won’t actually lazy load the images.
This is because the display:none feature is applied using javascript, which is too late in the page load. It would need to be applied using PHP before the page renders, since the browser will run this script after parsing the HTML and CSS.
]]>Hello
i have some problem.
I tried and tested your plugin, I made a setup like this
https://prntscr.com/ndv9le
just to be sure that images are being lazy loaded and they are but gtmatrix show different.
it show that all images are being loaded..
how to fix this ??
Thanks
]]>Hi,
I’ve installed the plugin in order to lazy load the landing page of https://www.dangerpress.com
It doesn’t seem to be having any effect.
Is there something I can specify somewhere to lazy load content below 500px?
Thanks,
J
]]>Hello,
Is there a filter so that it is only enabled in background images?
Tks
]]>Please, change this:
if (myClasses.some(v => skipClasses.indexOf(v) >= 0)) {
to this:
if (myClasses.some(function (v) { return skipClasses.indexOf(v) >= 0; })) {
in image_lazy_load.js.
IE does’n support arrow function. Thanks.
]]>After the last update from 3 days ago it seems that there are a few things not working anymore as expected caused by a javascript error (Not on all pages, but on some). I will try the last version again as a workaround, but this is fyi…
I now get the following error in the console:
image_lazy_load.js:24 Uncaught TypeError: image.className.split is not a function
at myClasses (image_lazy_load.js:24)
at SVGSVGElement.<anonymous> (image_lazy_load.js:118)
at Function.each (jquery.js:2)
at a.fn.init.each (jquery.js:2)
at HTMLDocument.<anonymous> (image_lazy_load.js:117)
at i (jquery.js:2)
at Object.fireWith [as resolveWith] (jquery.js:2)
at Function.ready (jquery.js:2)
at HTMLDocument.K (jquery.js:2)
Please advise, will it work with woocommerce / storefront theme?
thanks.
]]>ok this breks the icons on Super Socializer. I excluded one parent css and got the page and post share icons back but the login ones wont coe back at all how do i add more than one parent to skip
]]>Hi,
Does your plugin work with advanced custom fields?
Thanks
]]>When I turn on Zedna WP Image Lazy Load thumbnail in foogallery are black.
I have autooptimize and foogallery plugin. They for work together need exclude from autooptimize foogallery.min.js. Meybe Zenda needs the same?
]]>Do you support Lazy load css background images?
If we should swap from wp rockets lazy load we need to be able to adjust lazyload threshold and ability to add “Fade In Effect for your LazyLoaded images” is this possible with your plugin if so could you provide me with the code here that is needed?
https://docs.wp-rocket.me/article/113-fade-in-effect-for-your-lazyloaded-images
https://docs.wp-rocket.me/article/1032-adjust-lazyload-threshold
Neither does this plugin work when using defer for javascripts.
Might need to exclude this plugins js? If so please send me the path.
]]>In wp 4.9.1, the wordpress admin breaks (This page isn’t working) when trying to activate the plugin.
debug.log is empty
]]>In the field: Skip images in parent element (css class without dot “.”)
Can we set more than one css class, as the classes are different in different webpages, so this plugin is currently working only on the homepage by lazy loading the background-image of the homepage. On other pages, however, it doesn’t work since we cannot specify more than one class. Is there a way to add more classes to skip?
Lazy loading for background images is implemented with javascript. At least in some scenario’s, this will not work. I’m using Visual Composer and checking my site in Chrome.
With F12, I can see that the “background-image: none !important” is set, but the images is still gets loaded on the network tab.
In general, it’s hard to guarantee lazy loading with pure JS, but it might make sense to add a warning about this somewhere.
]]>Adsense not loading properly when i enabled lazy iframe..
Adsense keeps refreshing automatically. it looks weird and revenue loss as well…
Kindly help
]]>Hi,
after the new update released now my Loading page plugin stop to work
https://it.www.ads-software.com/plugins/loading-page/
I really need remove this broken plugin version and go back to the previous who was working.
]]>Thank you for spending the time to create this plugin. When attempting to implement this on my website, I ran into a problem.
Lazy loading gradient backgrounds is not necessary and it breaks the background from loading.
Example CSS3:
background:linear-gradient(90deg,rgba(130,130,130,0.95) 5%,rgba(255,255,255,0.95) 52%);
Gradient backgrounds should be skipped by the plugin.
To see other gradient examples, visit: https://www.w3schools.com/css/css3_gradients.asp
Thanks!
]]>Hi,
the plug-in is working very well but I have an issue in some page generated with
https://it.www.ads-software.com/plugins/content-views-query-and-display-post-page/
As you can see at the bottom of the page:
– https://www.peopleinside.it/video/musicali/
– https://www.marcoborla.it/blog/
in the footer near number of pages a loading icon is always showed.
Can you please fix this?
Thank you!
So I guess it happened after the update.
Been working fine with no issues whatsoever, but then I updated, and well, all the other photos are loading just fine, but the featured photo of the post is showing blank.
Now I deactivated it.
Any idea?
]]>Hello! I gotta say, I love your plugin! I had one quick question though. I am using it on my site, but the iframe I am using the plugin to lazyload loads in very suddenly. Is there any way to get it to fade transition in? I want it to look a bit more smooth, especially on mobile. If this is outside the scope of your support, I totally understand.
Thanks!!
]]>Hi,
I noticed that the images set as background in CSS are downloaded twice, once when the page loads and again when the page scrolls.
if I set the image url in the background-image-backup tag everything works fine, but I would use style = “background-image: url (…)” ad usual.
thanks!
]]>