{"id":28151,"date":"2022-03-29T15:51:31","date_gmt":"2022-03-29T15:51:31","guid":{"rendered":"http:\/\/asynchronously-load-and-decode-images"},"modified":"2025-02-08T18:05:07","modified_gmt":"2025-02-09T02:05:07","slug":"asynchronously-load-and-decode-images","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/","title":{"rendered":"How to asynchronously load and decode images"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p>Images are an increasingly important part of the web. The ability to retain visual information is one of the many reasons we find images appealing, and this makes images more effective at conveying ideas across cultures. Imagine a website without images? Boring! However, if images aren\u2019t properly optimized, they can cause a lot of performance issues (such as taking up the loading resources), which can negatively impact the user experience on your website.<\/p>\n<p>Before an image is displayed in the browser, it has to be loaded from the server first. Next, the browser has to read the data and convert it into something that the browser can display \u2014 a process known as decoding. After that, the result is painted on the screen. If you\u2019re looking to get the most out of your images, this post will discuss how to asynchronously load and decode images on your website to improve page load performance and user experience.<\/p>\n<p>Here is a <a href=\"https:\/\/codesandbox.io\/s\/async-load-and-decode-images-syrh5z\">link<\/a> to the demo on CodeSandbox.<\/p>\n<\/div>\n  \n  <div class=\"wp-block-cloudinary-code-sandbox \">\n    <iframe\n      src=\"https:\/\/codesandbox.io\/embed\/async-load-and-decode-images-syrh5z?theme=dark&amp;codemirror=1&amp;highlights=&amp;editorsize=50&amp;fontsize=14&amp;expanddevtools=0&amp;hidedevtools=0&amp;eslint=0&amp;forcerefresh=0&amp;hidenavigation=0&amp;initialpath=%2F&amp;module=&amp;moduleview=0&amp;previewwindow=&amp;view=&amp;runonclick=1\"\n      height=\"500\"\n      style=\"width: 100%;\"\n      title=\"async-load-and-decode-images-syrh5z\"\n      loading=\"lazy\"\n      allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n    ><\/iframe>\n  <\/div>\n\n  <div class=\"wp-block-cloudinary-markdown \"><h2>Native Image Lazy-Loading<\/h2>\n<p>The browser will attempt to load everything on a web page at once, and as a result, the page takes longer to load if it contains lots of images because, as explained, images take time to process. With lazy loading, you can prioritize the important images in the user\u2019s initial viewport. There are different JavaScript-based solutions for lazy loading images, but in this post, we will look at how to lazy-load images using the <code>loading<\/code> attribute of the <code>&lt;img&gt;<\/code> element.<\/p>\n<p>Lazy loading is a web performance technique that delays loading images that are offscreen until they are close to the user\u2019s viewport, rather than loading them upfront (immediately the page loads). With modern browsers (Chrome, Edge, Firefox) supporting this feature, all you need to do to lazy load an image is add a <code>loading<\/code> attribute to an <code>&lt;img&gt;<\/code> element and set its value to <code>lazy<\/code>.<\/p>\n<p>The supported values for the loading attribute are <code>auto<\/code>, <code>eager<\/code>, and <code>lazy<\/code>, where <code>auto<\/code> is the browser\u2019s default behavior. Setting the value of the <code>loading<\/code> attribute to <code>lazy<\/code> tells the browser to deprioritize loading the image when the page loads and fetch it as soon as possible or when the user is about to see them as they scroll.<\/p>\n<p>Let\u2019s take an example. Run these commands in your terminal to create an <code>index.js<\/code> file in a folder named <code>async-load-decode-images<\/code>.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">    mkdir <span class=\"hljs-keyword\">async<\/span>-load-decode-images\n    cd <span class=\"hljs-keyword\">async<\/span>-load-decode-images\n    touch index.html\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Create a folder called <code>images<\/code> at the root of your project and add six images in <code>jpeg<\/code> file format to it. The images should be named <code>image1<\/code>, <code>image2<\/code>, and so on until the sixth. You can get free images from <a href=\"https:\/\/unsplash.com\/\">Unsplash<\/a>.<\/p>\n<p>After that, add the following to your <code>index.js<\/code> file:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">    <span class=\"hljs-meta\">&lt;!DOCTYPE <span class=\"hljs-meta-keyword\">html<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">html<\/span> <span class=\"hljs-attr\">lang<\/span>=<span class=\"hljs-string\">\"en\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">charset<\/span>=<span class=\"hljs-string\">\"UTF-8\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">http-equiv<\/span>=<span class=\"hljs-string\">\"X-UA-Compatible\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"IE=edge\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"viewport\"<\/span> <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"width=device-width, initial-scale=1.0\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>Lazy Loading Images<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"stylesheet\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"styles.css\"<\/span> \/&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">head<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">header<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>Lazy Loading Images<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">header<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">main<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n                <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"eager\"<\/span>\n                <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image1.jpeg\"<\/span>\n                <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n              \/&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker, including versions of Lorem Ipsum<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n                <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"eager\"<\/span>\n                <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image2.jpeg\"<\/span>\n                <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n              \/&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n                  <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"eager\"<\/span>\n                  <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image3.jpeg\"<\/span>\n                  <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n                \/&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>There are many variations of passages of Lorem Ipsum available, but the majority have suffered alteration in some form, by injected humour, or randomised words which don't look even slightly believable. If you are going to use a passage of Lorem Ipsum, you need to be sure there isn't anything embarrassing hidden in the middle of text. All the Lorem Ipsum generators on the Internet tend to repeat predefined chunks as necessary, making this the first true generator on the Internet.<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n                  <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"lazy\"<\/span>\n                  <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image4.jpeg\"<\/span>\n                  <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n                \/&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of \"de Finibus Bonorum et Malorum\" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, \"Lorem ipsum dolor sit amet..\", comes from a line in section 1.10.32. The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n                <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"lazy\"<\/span>\n                <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image5.jpeg\"<\/span>\n                <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n              \/&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source.<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n                <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"lazy\"<\/span>\n                <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image6.jpeg\"<\/span>\n                <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n              \/&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">p<\/span>&gt;<\/span>The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">p<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">section<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">main<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">body<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">html<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>In the code above, we have six <code>&lt;img&gt;<\/code> tags with specified <code>width<\/code> and <code>height<\/code> attributes. We set the value of the <code>loading<\/code> attribute in the first three <code>img<\/code> tags to <code>eager<\/code> so that they can be loaded immediately because when the page loads, they are in the first visible viewport. The <code>loading<\/code> attribute in the last three images is set to <code>lazy<\/code> because they are below the viewport, so we don\u2019t want them to be loaded on page load until the user approaches them.<\/p>\n<p>If you open this page in your browser (I\u2019m using Chrome), you should see all six images. Now to open the Developer Tools on that page, <strong>right click<\/strong>, click <strong>Inspect<\/strong> then, then navigate to <strong>Network<\/strong> and reload the page.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cloudinary-marketing-res.cloudinary.com\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/media_jams\/s_99E751C8515B7A70195A30947BF4906EB32888D17191244CBB47A4249027920A_1645853457206_CleanShot+2022-02-26+at+09.29.16.gif\" alt=\"\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"800\" height=\"457\"\/><\/p>\n<p>The Network tab in the gif above shows that the first three images are loaded when you reload the page. Then as I scroll the page, the other images get loaded. When we use the Chrome network throttler in the dev tools to simulate a slower network connection (slow 3G), the first three images are loaded first, followed by the last three images, which are lazy-loaded.<\/p>\n<p>Notice how we didn\u2019t need to scroll down the page even on a slow network, and the last three images were fully loaded. This is because <a href=\"https:\/\/addyosmani.com\/blog\/better-image-lazy-loading-in-chrome\/\">significant improvements<\/a> (new distance-from-viewport thresholds) were made to <code>&lt;img&gt;<\/code> lazy-loading in Chrome, as lazy-loaded images may not be fully loaded before entering the browser\u2019s viewport. These improvements allow offscreen images that are nearby to be loaded early, ensuring that they have finished loading and are visible by the time a user scrolls to them.<\/p>\n<blockquote>\n<p>Note that the size of an image can also affect the time it takes to load the image. Even if the loading attribute is set to <code>eager<\/code>, larger images take longer to load. You can explore that by adding large images and checking the network tab in the Dev Tools.<\/p>\n<\/blockquote>\n<h2>HTML <code>&lt;img&gt;<\/code> Decoding Attribute<\/h2>\n<p>As explained earlier, before an image is displayed in the browser, it has to be loaded and decoded. The problem is that decoding is an expensive process, and because JavaScript is single-threaded, decoding happens synchronously on the main thread.<\/p>\n<p>Because the browser loads all the resources (text, images) on a web page synchronously before rendering the page, it would take longer to decode heavy or multiple images on a page. This would delay the rendering of the page, causing the UI to freeze until it is complete.<\/p>\n<p>Several factors (image size, format, etc.) contribute to the time it takes to display an image. Still, the time it takes to decode an image is very important in determining when to load the image once it has been downloaded.<\/p>\n<p>One way to control image decoding and improve image load times is to use the <code>decoding<\/code> attribute of the HTML <code>&lt;img&gt;<\/code> element and set it\u2019s value to <code>async<\/code> like so:<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">img<\/span>\n    <span class=\"hljs-attr\">loading<\/span>=<span class=\"hljs-string\">\"lazy\"<\/span>\n    <span class=\"hljs-attr\">src<\/span>=<span class=\"hljs-string\">\".\/images\/image6.jpeg\"<\/span>\n    <span class=\"hljs-attr\">alt<\/span>=<span class=\"hljs-string\">\"Image from https:\/\/unsplash.com\/\"<\/span>\n    <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"400\"<\/span> <span class=\"hljs-attr\">height<\/span>=<span class=\"hljs-string\">\"400\"<\/span>\n    <span class=\"hljs-attr\">decoding<\/span>=<span class=\"hljs-string\">\"async\"<\/span>\n    \/&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>This way, image decoding happens asynchronously (off the main thread), leaving the main thread free so the browser can continue rendering the other content of the page. It defers the image decoding until later and displays it when it is done.<\/p>\n<p>The <code>decoding<\/code> attribute is supported by all major browsers (Chrome, Edge, and Firefox), and it accepts three values:<\/p>\n<p><code>auto<\/code>: up to the browser to decide between <code>sync<\/code> or <code>async<\/code> decoding.\n<code>sync<\/code>: images and other page resources are rendered at the same time on the main thread.\n<code>async<\/code>: tells the browser to continue rendering other page content and display the image when the decoding is complete. This makes rendering faster and is preferred for performance.<\/p>\n<p>You can find the project <a href=\"https:\/\/github.com\/ifeoma-imoh\/async-load-and-decode-images\">here<\/a> on Github.<\/p>\n<h2>Conclusion<\/h2>\n<p>This post explored how to asynchronously load and decode images to significantly improve page load performance, save cost (data) and improve user experience.<\/p>\n<p>Resources you may find useful:<\/p>\n<ul>\n<li>\n<a href=\"https:\/\/addyosmani.com\/blog\/better-image-lazy-loading-in-chrome\/\">Improvements to image lazy-loading in Chrome<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/css-tricks.com\/preventing-content-reflow-from-lazy-loaded-images\/\">Prevent content reflow from lazy-loaded images<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/HTMLImageElement\/decoding\">HTMLImageElement.decoding &#8211; MDN<\/a>\n<\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":41,"featured_media":28152,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[134,370,186,371],"class_list":["post-28151","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-guest-post","tag-image","tag-lazy-loading","tag-under-review"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>How to asynchronously load and decode images<\/title>\n<meta name=\"description\" content=\"In this post, we will go through how to asynchronously load and decode images on your website to improve page load performance and user experience.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to asynchronously load and decode images\" \/>\n<meta property=\"og:description\" content=\"In this post, we will go through how to asynchronously load and decode images on your website to improve page load performance and user experience.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-29T15:51:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-09T02:05:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190-png?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"How to asynchronously load and decode images\",\"datePublished\":\"2022-03-29T15:51:31+00:00\",\"dateModified\":\"2025-02-09T02:05:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\"},\"wordCount\":7,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA\",\"keywords\":[\"Guest Post\",\"Image\",\"Lazy Loading\",\"Under Review\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\",\"name\":\"How to asynchronously load and decode images\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA\",\"datePublished\":\"2022-03-29T15:51:31+00:00\",\"dateModified\":\"2025-02-09T02:05:07+00:00\",\"description\":\"In this post, we will go through how to asynchronously load and decode images on your website to improve page load performance and user experience.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA\",\"width\":1280,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to asynchronously load and decode images\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to asynchronously load and decode images","description":"In this post, we will go through how to asynchronously load and decode images on your website to improve page load performance and user experience.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/","og_locale":"en_US","og_type":"article","og_title":"How to asynchronously load and decode images","og_description":"In this post, we will go through how to asynchronously load and decode images on your website to improve page load performance and user experience.","og_url":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/","og_site_name":"Cloudinary Blog","article_published_time":"2022-03-29T15:51:31+00:00","article_modified_time":"2025-02-09T02:05:07+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190-png?_i=AA","type":"image\/png"}],"twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/"},"author":{"name":"","@id":""},"headline":"How to asynchronously load and decode images","datePublished":"2022-03-29T15:51:31+00:00","dateModified":"2025-02-09T02:05:07+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/"},"wordCount":7,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA","keywords":["Guest Post","Image","Lazy Loading","Under Review"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/","url":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/","name":"How to asynchronously load and decode images","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA","datePublished":"2022-03-29T15:51:31+00:00","dateModified":"2025-02-09T02:05:07+00:00","description":"In this post, we will go through how to asynchronously load and decode images on your website to improve page load performance and user experience.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA","width":1280,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/asynchronously-load-and-decode-images\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to asynchronously load and decode images"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":""}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681925291\/Web_Assets\/blog\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190\/406cb21e3d9b36b365787ceef419126908c97f99-1280x720-1_281528e190.png?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=28151"}],"version-history":[{"count":1,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28151\/revisions"}],"predecessor-version":[{"id":36760,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28151\/revisions\/36760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/28152"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=28151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=28151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=28151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}