Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 512573

Fixed: srcset priority bug. Please merge

$
0
0

Replies: 0

In line 57 of /wp-content/plugins/bj-lazy-load/js/bj-lazy-load.js, you have this


if ( 'image' == type ) {
	el.setAttribute( 'src', el.getAttribute('data-lazy-src') );
	if ( null != el.getAttribute('data-lazy-srcset') ) {
		el.setAttribute( 'srcset', el.getAttribute('data-lazy-srcset') );
	}
}

It sets the src attribute first, then the srcset attribute. That causes the browser to download both the original image and the responsive version. We’ve changed it to the code below and the problem is fixed. This should be included in the upcoming versions.


if ( 'image' == type ) {
	if ( null != el.getAttribute('data-lazy-srcset') ) {
		el.setAttribute( 'srcset', el.getAttribute('data-lazy-srcset') );
	}
	el.setAttribute( 'src', el.getAttribute('data-lazy-src') );
}

Here’s all the code that should go in /wp-content/plugins/bj-lazy-load/js/bj-lazy-load.min.js


"use strict";var BJLL_options=BJLL_options||{},BJLL={_ticking:!1,check:function(){if(!BJLL._ticking){BJLL._ticking=!0,"undefined"==typeof BJLL.threshold&&("undefined"!=typeof BJLL_options.threshold?BJLL.threshold=parseInt(BJLL_options.threshold):BJLL.threshold=200);var a=document.documentElement.clientHeight||body.clientHeight,b=!1,c=document.getElementsByClassName("lazy-hidden");[].forEach.call(c,function(c,d,e){var f=c.getBoundingClientRect();a-f.top+BJLL.threshold>0&&(BJLL.show(c),b=!0)}),BJLL._ticking=!1,b&&BJLL.check()}},show:function(a){a.className=a.className.replace(/(?:^|\s)lazy-hidden(?!\S)/g,""),a.addEventListener("load",function(){a.className+=" lazy-loaded",BJLL.customEvent(a,"lazyloaded")},!1);var b=a.getAttribute("data-lazy-type");if("image"==b)null!=a.getAttribute("data-lazy-srcset")&&a.setAttribute("srcset",a.getAttribute("data-lazy-srcset")),a.setAttribute("src",a.getAttribute("data-lazy-src"));else if("iframe"==b){var c=a.getAttribute("data-lazy-src"),d=document.createElement("div");d.innerHTML=c;var e=d.firstChild;a.parentNode.replaceChild(e,a)}},customEvent:function(a,b){var c;document.createEvent?(c=document.createEvent("HTMLEvents"),c.initEvent(b,!0,!0)):(c=document.createEventObject(),c.eventType=b),c.eventName=b,document.createEvent?a.dispatchEvent(c):a.fireEvent("on"+c.eventType,c)}};window.addEventListener("load",BJLL.check,!1),window.addEventListener("scroll",BJLL.check,!1),window.addEventListener("resize",BJLL.check,!1),document.getElementsByTagName("body").item(0).addEventListener("post-load",BJLL.check,!1);

Viewing all articles
Browse latest Browse all 512573

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>