Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 4, 2022 01:06 pm GMT

Do you need the decoding attribute?

Do you know the decoding attribute for images? You can combine it with the loading attribute like that:

<img alt="" src="" decoding="async" loading="lazy">

Source: MDN

There are 3 possible values:

  • sync: force synchronous decoding
  • async: force asynchronous decoding
  • auto: let the browser decides (~ no preference) - the defaut value

Browser support is not that bad (~ 66% at the time of writing).

Pratically speaking, when the decoding attribute is set to async, the browser can parallelize the image decoding process, which might significantly improve the page rendering, as it can be an expensive operation, especially with large images.

async puts image decoding off the main thread and can thus save some CPU. As far as I know, it's safe to use even with browsers that do not support it yet.

Actually, async is not the default value probably because of some edge legacy issues, but I don't see why you would not use it in most cases.

Photo by afiq fatah


Original Link: https://dev.to/jmau111/do-you-need-the-decoding-attribute-6h7

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To