Skip to content

Instantly share code, notes, and snippets.

@inian
Last active June 13, 2019 14:42
Show Gist options
  • Save inian/2bd3a064854fa238b4dc859acc09743e to your computer and use it in GitHub Desktop.
Save inian/2bd3a064854fa238b4dc859acc09743e to your computer and use it in GitHub Desktop.
const img = new Image();
img.src = "cat.png";
img.decode().then(() => {
// image fully decoded and can be safely rendered on the screen
const orig = document.getElementById("orig");
orig.parentElement.replaceChild(img, orig);
});
<!-- Suggest to the browser that the decoding can be deferred -->
<img decoding="async" src="cat.png" >
<!-- Suggest to the browser that the decoding should not be deferred -->
<img decoding="sync" src="cat.png">
<!-- Let the browser figure it out -->
<img decoding="auto" src="cat.png">
<img src="cat.png">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment