const img = new Image();
img.decoding = "sync";
img.src = "img/logo.png";
document.body.appendChild(img);HTMLImageElement: decoding property / notebook
HTMLImageElement: decoding property
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
async function loadImage(url, elem) {
return new Promise((resolve, reject) => {
elem.onload = () => resolve(elem);
elem.onerror = reject;
elem.src = url;
});
}
const img = new Image();
await loadImage("img/logo.png", img);
// Using `sync` can ensure other content is only updated with the image
img.decoding = "sync";
document.body.appendChild(img);
const p = document.createElement("p");
p.textContent = "Image is fully loaded!";
document.body.appendChild(p);const img = new Image();
img.decoding = "async";
img.src = "img/logo.png";
document.body.appendChild(img);