lazy loading - what is it, and why should i use it?

have you ever been exploring a website until you reach any pages with lots of large images? does it suddenly slow down to a crawl? is there a header reading "images might take a while to load, sorry! :("

i've experienced this many times in the past, and if you're interested in seeing people's galleries like i am then you may have experienced it too. maybe you even are the webmaster who's had to put up a warning about slow loading times (no hard feelings on that front by the way, you aren't the only one!) and you want to know if there's any way to get around the issue.

well, is there?

yes, there is - it's called lazy loading!

lazy loading is used to prevent every single image on your site from loading at once, only allowing images that are near the border of your viewpoint to fully load - meaning that images will only load if you have scrolled near them.

the main goal of the lazy loading is performance. using lazy loading will generally speed up load times on your image-heavy pages.

wow, how can i implement this "lazy loading" into my own site?

it's actually pretty easy to add lazy loading to your images!

  1. grab your image.

    melonland's surf club logo

  2. find the code for your image in your html file.

    a screenshot of html code. it reads 'image src = images/surfclub.png'.

  3. add the text loading="lazy" to your code.

    a screenshot of html code. it reads 'image src = images/surfclub.png loading = lazy'.

and there you go! unfortunately i haven't been able to show off an example of lazy loading in practice, but i can direct you to sites that can. i don't like google, but lazy loading is used by google images to display as many images as possible as quickly as possible.

neat, i should change all my images to have lazy loading right away!

woah, hang on a moment! while lazy loading can be useful, it isn't always necessary! for example, sites such as wikipedia often don't use lazy loading because they just don't need to - they are primarily text-based, and their images don't take up many resources because they just don't have very many.

likewise, lazy loading only affects images that you need to scroll to see. if all of your images can be seen without scrolling, then lazy loading won't have any effect anyways.

conclusion

i hope this article is able to help anyone out with slow-loading sites caused by having lots of images! this is my first article, and while i did do a tiny bit of research for this, a lot of it is based on my own experiences with web development :']