Chestnut
0) { elemWidth = imgWidth; } else if(parentWidth>0) { elemWidth = parentWidth; } else { elemWidth = dWidth; } if(!src) { src = origsrc; //console.log("NO IMAGE "+src); } if(src.includes(".png")) { img.src = src; return; } iwidth = (Math.floor((elemWidth+5)/10)*10); if(iwidth==0) { img.src = src; return; } if(dataCheck) { var checkProtocol = window.location.protocol, checkHostname = window.location.hostname, checkUrl = new URL(checkProtocol+checkHostname+dataCheck); if(checkUrl.searchParams.get("_mimin") && checkUrl.searchParams.get("_mimin")>iwidth) { iwidth = checkUrl.searchParams.get("_mimin"); console.log("ittps _mimin detected "+checkUrl.searchParams.get("_mimin")); } else if(checkUrl.searchParams.get("_mimax") && checkUrl.searchParams.get("_mimax") { if (res.ok) { src = "/media/mimage/"+iwidth+testUrl; //console.log("/media/mimage/"+iwidth+dataCheck+" exist."); img.src = src; img.classList.add("_magicResized"); } else { fetch("/media/mimage/"+iwidth+testUrl, { method: "HEAD" }) .then(res => { if (res.ok) { src = "/media/mimage/"+iwidth+testUrl; //console.log("/media/mimage/"+iwidth+dataCheck+" exist."); img.src = src; img.classList.add("_magicResized"); } else { src = "/mimage.php?url="+src+"&iwidth="+iwidth+"&dwidth="+dWidth; //console.log("/media/mimage/"+iwidth+dataCheck+" does not exist."); img.src = src; img.classList.add("_magicResized"); } }).catch(err => console.log("Error:", err)); } }).catch(err => console.log("Error:", err)); } } var dWidthTwo = document.body.clientWidth; /*const meImgsTwo = document.querySelectorAll("[src-two]"); setTimeout(function(){ meImgsTwo.forEach(img => { preloadImageTwo(img, dWidthTwo); }); }, 0);*/