UPDATE: This is pretty old. Image meta data handling implementation based on the help and contribution of Achim Stöhr. The following code loads the app.js file after the page has been completely loaded. Include the (minified) JavaScript Load Image script in your HTML markup: Or alternatively, choose which components you want to include: In your application code, use the loadImage() function like this: It is also possible to use the image scaling functionality with an existing image: The JavaScript Load Image library has zero dependencies. It is simple to load images to the page using JavaScript. Photo by Caspar Camille Rubin on Unsplash. The loadImage() function is used to load an image from the given path and create a p5.Image object with the image. Loading an image on the website can require a long time. It returns an optionally scaled and/or cropped HTML img or canvas element. Apart from being able to lazy load images and background images, you can also serve up different lazy images based on device sizes, such as one image for 480px or less devices, and another for 720px or less etc. The resize and orientationChange events are equally important for lazy loading. Finally, insert it to the document. However, you may still need a third-party JavaScript library to implement the lazy load functionality on cross-browser projects. Draw the image on the canvas using the drawImage() function. That’s wasteful. This is extremely useful for reloading a captcha image if the user is unable to read the characters shown in it. Whether you’re loading a high-resolution image in an image gallery or you have a game with lots of image assets and sprites, the code will do something like this. Assign a URL to the srcattribute of the new image 3. Lazy load image using the Intersection Observer API is not supported on all browsers. ; Let's take a … } /* * Use $(window).load() instead of $(document).ready() because we wan't to start caching images * as soon as the progress bar images are loaded. The 10 Best Lazy Load JavaScript Libraries: 1. Unlike the images, the web browser starts downloading JavaScript files only after the src property has been assigned and the