{"id":9053677,"date":"2017-04-21T15:22:08","date_gmt":"2017-04-21T15:22:08","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/srcset-priority-bug\/"},"modified":"2017-04-21T15:25:42","modified_gmt":"2017-04-21T15:25:42","slug":"srcset-priority-bug","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/srcset-priority-bug\/","title":{"rendered":"Fixed: srcset priority bug. Please merge"},"content":{"rendered":"<p>In line 57 of \/wp-content\/plugins\/bj-lazy-load\/js\/bj-lazy-load.js, you have this<\/p>\n<pre><code>\nif ( &#039;image&#039; == type ) {\n\tel.setAttribute( &#039;src&#039;, el.getAttribute(&#039;data-lazy-src&#039;) );\n\tif ( null != el.getAttribute(&#039;data-lazy-srcset&#039;) ) {\n\t\tel.setAttribute( &#039;srcset&#039;, el.getAttribute(&#039;data-lazy-srcset&#039;) );\n\t}\n}\n<\/code><\/pre>\n<p>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&#8217;ve changed it to the code below and the problem is fixed. This should be included in the upcoming versions.<\/p>\n<pre><code>\nif ( &#039;image&#039; == type ) {\n\tif ( null != el.getAttribute(&#039;data-lazy-srcset&#039;) ) {\n\t\tel.setAttribute( &#039;srcset&#039;, el.getAttribute(&#039;data-lazy-srcset&#039;) );\n\t}\n\tel.setAttribute( &#039;src&#039;, el.getAttribute(&#039;data-lazy-src&#039;) );\n}\n<\/code><\/pre>\n<p>Here&#8217;s all the code that should go in \/wp-content\/plugins\/bj-lazy-load\/js\/bj-lazy-load.min.js<\/p>\n<pre><code>\n&quot;use strict&quot;;var BJLL_options=BJLL_options||{},BJLL={_ticking:!1,check:function(){if(!BJLL._ticking){BJLL._ticking=!0,&quot;undefined&quot;==typeof BJLL.threshold&amp;&amp;(&quot;undefined&quot;!=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(&quot;lazy-hidden&quot;);[].forEach.call(c,function(c,d,e){var f=c.getBoundingClientRect();a-f.top+BJLL.threshold&gt;0&amp;&amp;(BJLL.show(c),b=!0)}),BJLL._ticking=!1,b&amp;&amp;BJLL.check()}},show:function(a){a.className=a.className.replace(\/(?:^|\\s)lazy-hidden(?!\\S)\/g,&quot;&quot;),a.addEventListener(&quot;load&quot;,function(){a.className+=&quot; lazy-loaded&quot;,BJLL.customEvent(a,&quot;lazyloaded&quot;)},!1);var b=a.getAttribute(&quot;data-lazy-type&quot;);if(&quot;image&quot;==b)null!=a.getAttribute(&quot;data-lazy-srcset&quot;)&amp;&amp;a.setAttribute(&quot;srcset&quot;,a.getAttribute(&quot;data-lazy-srcset&quot;)),a.setAttribute(&quot;src&quot;,a.getAttribute(&quot;data-lazy-src&quot;));else if(&quot;iframe&quot;==b){var c=a.getAttribute(&quot;data-lazy-src&quot;),d=document.createElement(&quot;div&quot;);d.innerHTML=c;var e=d.firstChild;a.parentNode.replaceChild(e,a)}},customEvent:function(a,b){var c;document.createEvent?(c=document.createEvent(&quot;HTMLEvents&quot;),c.initEvent(b,!0,!0)):(c=document.createEventObject(),c.eventType=b),c.eventName=b,document.createEvent?a.dispatchEvent(c):a.fireEvent(&quot;on&quot;+c.eventType,c)}};window.addEventListener(&quot;load&quot;,BJLL.check,!1),window.addEventListener(&quot;scroll&quot;,BJLL.check,!1),window.addEventListener(&quot;resize&quot;,BJLL.check,!1),document.getElementsByTagName(&quot;body&quot;).item(0).addEventListener(&quot;post-load&quot;,BJLL.check,!1);\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-9053677","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9053677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":3,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9053677\/revisions"}],"predecessor-version":[{"id":9053707,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/9053677\/revisions\/9053707"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=9053677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}