Title: Fixed: srcset priority bug. Please merge
Last modified: April 21, 2017

---

# Fixed: srcset priority bug. Please merge

 *  [Lucian Florian](https://wordpress.org/support/users/fldtrace/)
 * (@fldtrace)
 * [9 years, 1 month ago](https://wordpress.org/support/topic/srcset-priority-bug/)
 * 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);
       ```
   
    -  This topic was modified 9 years, 1 month ago by [Lucian Florian](https://wordpress.org/support/users/fldtrace/).
    -  This topic was modified 9 years, 1 month ago by [Lucian Florian](https://wordpress.org/support/users/fldtrace/).
    -  This topic was modified 9 years, 1 month ago by [Lucian Florian](https://wordpress.org/support/users/fldtrace/).

Viewing 1 replies (of 1 total)

 *  Plugin Author [arontornberg](https://wordpress.org/support/users/arontornberg/)
 * (@arontornberg)
 * [8 years, 9 months ago](https://wordpress.org/support/topic/srcset-priority-bug/#post-9394401)
 * Thank you!
 * This fix has now been added to the plugin.

Viewing 1 replies (of 1 total)

The topic ‘Fixed: srcset priority bug. Please merge’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/bj-lazy-load_9084ba.svg)
 * [BJ Lazy Load](https://wordpress.org/plugins/bj-lazy-load/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/bj-lazy-load/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/bj-lazy-load/)
 * [Active Topics](https://wordpress.org/support/plugin/bj-lazy-load/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/bj-lazy-load/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/bj-lazy-load/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [arontornberg](https://wordpress.org/support/users/arontornberg/)
 * Last activity: [8 years, 9 months ago](https://wordpress.org/support/topic/srcset-priority-bug/#post-9394401)
 * Status: not resolved