Lazy loading images for website using jQuery plugin

Images play a vital role in enhancing the visual appeal of a website. However, large image files can significantly slow down page load times, leading to a poor user experience and hurting SEO. That’s where the jQuery Lazy Load plugin comes to the rescue!

In this post, we will walk you through the process of using this handy plugin to effortlessly load images on your website, improving performance and user satisfaction.

What is jQuery Lazy Load Plugin?

jQuery Lazy Load is a lightweight JavaScript plugin that helps optimize the loading of images on web pages. Instead of loading all the images at once, it allows you to delay the loading of images until they are about to be displayed within the user’s viewport. This technique is known as “lazy loading” and can significantly speed up the initial page load.

Download and Include the jQuery and Lazy Load Plugin

Before using the Lazy Load plugin, you need to ensure that you have the jQuery library included in your web page. You can find the plugin on the official jQuery Lazy Load GitHub repository.

You can either download both libraries or include them from a content delivery network (CDN). In this example, we will use CDNs:

<script src=""></script>
<script src=""></script>

Include both script tags at the head section of a document or end of the body element. We prefer to load it at the end of body.

Define Image Elements with Lazy Loading

To enable lazy loading for your images, you need to modify their HTML markup slightly. Replace the src attribute with data-src and add a class or ID to target them with jQuery. For example:

<img class="lazy" data-src="path/to/image.jpg" alt="Example Image">

Initialize the Lazy Load Plugin

At last, we will initialize the Lazy Load plugin using jQuery. Add the below code after CDN links:

$(document).ready(function() {

    // Example with some configurations
        effect: 'fadeIn',
        visibleOnly: true,

Here, we have used the .lazy class to target elements that are loaded after a document is ready. Here, we have taken 2 examples. Both will load images using lazy method. But in the second method, we have added some optional parameters like effect.

The Lazy Load plugin provides additional options for customization. You can specify a different loading image, adjust the delay time, or add effects to the image loading process. Refer to the plugin’s documentation for more details on available options and their usage.

Let’s see what full implementation looks like in minimum mode:

<!DOCTYPE html>
        <title>Lazy Load Plugin Example</title>
        <img class="lazy" data-src="path/to/image1.jpg" alt="Example Image 1">
        <img class="lazy" data-src="path/to/image2.jpg" alt="Example Image 2">
        <img class="lazy" data-src="path/to/image3.jpg" alt="Example Image 3">

        <script src=""></script>
        <script src=""></script>
            $(document).ready(function() {


With the jQuery Lazy Load plugin, optimizing image loading on your website has never been easier. By deferring the loading of images until they are visible within the user’s viewport, you can dramatically enhance performance and improve user satisfaction.