Slash Coding

  • Android Development
  • CSS
  • Subscribe
  • About Us
  • Contact Us
You are here: Home / Developer Tips / Lazy Load Images to Boost Webpage Load Time

Lazy Load Images to Boost Webpage Load Time

By Aneesh Bhatnagar

Creating Fast and quick loading web pages are the things a client wants these days. Moreover, the developer themselves want to create such pages. There are various ways to boost up your page loading time, one of them being optimizing your images for a quick page load. Now, to optimize your images, there are two things you can do, either decrease the quality of your image and reduce its size or you can Lazy load your images with this trick to decrease your page loading time greatly.

Lazy PersonWell, if you are unaware about Lazy Loading, let me tell you what is Lazy Loading. Lazy Loading is a technique to load a blank image of a fixed dimension on the webpage at first, but when the image gets in the area where the user can view it, it loads the actual image at that place. This decreases the initial page loading time and the customer/user is happy! I guess that’s what matters these days, happy people!

Let’s get started with this simple tutorial to help you boost your page loading time. This is a preview of what we are going to do in this tutorial.

Lazy Load Preview

Lazy Loading Images on your Webpage

For lazy loading images, we need to add some jQuery to our webpage and change the HTML markup of our page. Let’s get started with changing the HTML first.

  1. First, create a blank image to use at the beginning of your page load. If you are LAZY to do that, simply save the following image.
  2. In your HTML page, on the images where you want to lazy load, change the following things.
    • change the word “src” to “data-original”
    • add a class and set it to “lazy”
    • add a src attribute and set it to “blank.png”

    Well, this is how your image tag should look like now.

    <img src="blank.png" data-original="image.png" alt="Enter your ALT Text here."/>
    
  3. Now, head over to the head tag of your page and include a few jQuery plugins. But before that, you need to download the Lazy Load jQuery plugin from github.
  4. After you have downloaded the jQuery Lazy Load plugin, simply place it in the folder with the web page and include the following lines of code in your head tag.
    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"> </script>
    <script type="text/javascript" src="jquery.lazyload.min.js"></script>
    
  5. Now, we are almost done! We just need to enter a few more lines of code. Add the following lines just before closing the head tag on your page.
    <script type="text/javascript">
    $(document).ready(function() {
    $("img.lazy").lazyload();
    });
    </script>
    
  6. Well, that’s all! You just finished the tutorial.
    Lazy Loading HTML Code

I hope this tutorial helps you to get a better page loading time and have more happy users. Stay tuned to Slash Coding for more tips and tricks for jQuery, CSS, PHP and more! Stay subscribed via RSS Feeds, our Facebook page, or our Twitter Account. See you around! 😉

Did you enjoy this article?
Subscribe to our email alerts when we post something new so you don't miss out.

About Aneesh Bhatnagar

Aneesh Bhatnagar is a freelance web developer, who specializes in front-end website development with HTML5, CSS3 and jQuery. He believes in transforming the entire web into a Responsive Web. He also specializes in use of Bootstrap framework to get websites up and running.

Comments

  1. Paul says

    November 2, 2013 at 2:41 am

    The code in step 4 is all messed up…

    <script type="text/// <![CDATA[javascript”

    • Aneesh Bhatnagar says

      November 2, 2013 at 9:32 am

      Thank you for pointing it out! I have fixed it! 🙂

  2. Denis Ryabov says

    December 20, 2013 at 4:39 pm

    There is another jQuery plugin that allows to use lazy loading for images, videos (both html5 tag and iframe-embedded ones like YouTube, Vimeo, etc.) and different widgets (Facebook, Twitter, Google+, etc.): http://ressio.github.io/lazy-load-xt

    • Aneesh Bhatnagar says

      December 20, 2013 at 11:46 pm

      Thank you for letting everyone know about such a plugin! 🙂

  3. Patrick says

    February 3, 2014 at 3:09 am

    Great article man!

    Cheers
    Patrick

    • Aneesh Bhatnagar says

      February 9, 2014 at 11:33 am

      Thank you for sharing such a tool! 🙂

Search Slash Coding

Follow Us

RSS Feeds Facebook Twitter Follow Google+

Categories

  • Android Development
  • C++
  • Developer Tips
  • Slash Coding
  • Web Development
    • CSS
    • JavaScript
    • jQuery
    • PHP

Recently Published

  • Moving Ahead from Front End and Android Development
  • How to Export a Project from Android Studio
  • What is jQuery? Let’s Answer this Common Question today!
  • Mobile App Prototyping : Pixate Studio
  • How to Create a Countdown Timer using jQuery

Subscribe to Email Alerts

Eager to learn more from Slash Coding?
Sign up for daily email updates when anything new comes up. Get it straight in your inbox.

Follow Us on Social Media

RSS Feeds Facebook Twitter Follow Google+

Copyright © 2025 · Slash Coding · Powered by the Genesis Framework
Sitemap | Privacy Policy | About | Contact

×
Get Notified of the new Tutorials when they are posted!
Never miss any article update from Slash Coding. Subscribe to email alerts today!