Lazy Load Your Images To Significantly Speed Up Page Load Times

speed-portfolio-lazyload

I’d seen the effect on other pages while surfing the web for some time now. Where you are scrolling down and the images load into view as the page is scrolling down. I immediately knew when seeing the effect in action just how beneficial this is. For one thing all images on a page don’t get loaded; if the user scrolls down only then is bandwidth consumed, otherwise it does not. And another giant bonus is that WITHOUT those images loading down the page that the user can’t even see right away the top of the page loads much faster.

The effect is called “lazy loading” your images. It’s a piece of jquery written by Mika Tuupola called the Lazy Load Plugin for jQuery which he offers up on his blog here. In its most basic form it loads images as they come into your viewport window. You can read further about installation and options at his blog.

Usage is as easy as linking to jquery and the lazy load library (probably just before your closing </body> tag):

In the HTML you’ll need to modify your existing <img> tag code. You’ll add the class lazy, and instead of putting src=”path/example.jpg” put data-original=“path/example.jpg”. Your final img tag should look like this (note that without stated img width and heights the lazy load code may mess up):

So that’s it. You just have to call the function on the page and include and modifiers you’d like to use with the script. In my case for loading images with a Fade In effect, and 400 pixels before the viewport threshold, my code looks like this:

If you’d really like to grade your success do a page speed test before implementing the code, and then again after. Here’s a link for a good page speed tester: tools.pingdom.com/fpt/. It’s the one I used to create the graphic at the top of this post.

On my Portfolio Page where there are a lot of graphics in use, my page speed load time went from ~3 seconds to ~1.5 seconds.

Tags: , ,

Leave a Reply

Other tags used in my blog:

 (1)  (6)  (1)  (16)  (1)  (1)  (17)  (1)  (17)  (1)  (1)  (7)  (1)  (4)  (16)  (5)  (2)  (29)  (9)  (1)  (12)  (4)  (1)  (4)  (5)  (9)  (1)  (6)  (1)  (4)  (1)  (1)  (1)  (3)  (1)  (3)  (4)  (7)  (3)  (3)  (4)  (1)  (1)  (2)  (1)  (7)  (11)  (13)  (2)  (6)  (1)  (3)  (16)  (2)  (3)  (1)  (5)  (1)  (29)  (4)  (4)  (9)