How to Defer Offscreen images: Lazy load images in blogger
Lazy loading of images is a technique of preventing off-fold imagess from loading initially and it helps in achieving better page speed. Learn how you can defer offscreen images in blogger.
Recently I was trying to optimize my blogger’s pagespeed by implementing the recommendations from Pagespeed Insight, and I noticed the term “Defer OffScreen Images” or lazy-loading of images. This article will highlight this section.
Offscreen images are those which are present below the fond or those images that do not lie in the screen when a page loads. Since users can't see offscreen images when they load a page, a good mechanism to improvise pagespeed can be to load those images after a page is loaded. Do browsers follow this mechanism by default? Sadly No!
Browsers download and load all image files at once, causing a huge usage of bandwidth and slow page performance. So, how to overcome this? A single solution: Lazy loading of Images.
Lazy loading of images means to load image files on demands dynamically. In this tutorial, I will explain on how to lazy load images in blogger and how these impacts page speed.
Comparison of Same Page without Lazy Loading Of Images and With lazy loading
I will take a sample page from this website:
I tested this page on GTMetrix and Pagespeed Insight and the results were stunning.
Before Lazy Loading of Blogger Images on GTMetrix
After Lazy Loading of Blogger Images on GTMetrix
Before Lazy Loading of Blogger images : PageSpeed Insight
After Lazy Loading Of Blogger Images: PageSpeed Insight
Isn't that cool ?
How to lazy load images in blogger: Defer Offscreen Images?
Now you know lazy loading of images drastically improves web performance, let us add it to your website. Don't forget to backup your whole blog and its contents.
Go to Theme > Edit HTML and Search for
/body and add the following code above it.
Hey, I forgot to mention this plugin is based on Jquery. Search for
</head> and add following Jquery file above it.
To lazy load images on blogger homepage (for thumbnail images), search for code similar to following:
<img expr:alt='data:post.title' expr:title='data:post.title' expr:src='resizeImage(data:post.firstImageUrl, 225, "225:170")'/>
Now make some changes as mentioned below:
Now, we will add a super small size image in src attribute:
It is a good practice to add src attribute in
<img> tag as browsers substitute src attribute with data-src attribute once the image is in viewing region. Here is an information clarifying what are src and data-src attributes.
Here is the updated code:
<img class='lazy' expr:alt='data:post.title' expr:title='data:post.title' expr:data-src='resizeImage(data:post.firstImageUrl, 225, "225:170")' src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC' />
How to lazy load post body images in blogger?
By far, we have implemented lazy loading effect to images on blogger homepage. Now, it is time for deferring offscreen images on post body.
Unlike Wordpress, Blogger doesn't support implementing lazy loading to all post body images. One need to make changes manually.
Here is a sample of image tag in blogger(without anchor tag),
<img alt="Lazy loading images" border="0" data-original-height="483" data-original-width="800" src="https://1.bp.blogspot.com/-WuPnaglqSDU/XX94-Vu0OrI/AAAAAAAAMFw/xPc6DOvLI5kvi3uULG9VvertcRhYkR8NgCLcBGAsYHQ/s640/simpleup-clean-blogger-template.jpg" height="386" title="Lazy loading images" width="640" />
The modified image tag code will look something like this:
<img alt="Lazy loading images" border="0" class="lazy" data-original-height="483" data-original-width="800" data-src="https://1.bp.blogspot.com/-WuPnaglqSDU/XX94-Vu0OrI/AAAAAAAAMFw/xPc6DOvLI5kvi3uULG9VvertcRhYkR8NgCLcBGAsYHQ/s640/simpleup-clean-blogger-template.jpg" height="386" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB/AAffA0nNPuCLAAAAAElFTkSuQmCC" title="Lazy loading images" width="640" />
You have to do make this changes manually for each and every images present that you want to defer. In case, you have any dynamic method, please leave the code in the comment section.
Also Read: 21 Tested Ways To Speed Blog Loading Time
Verifying Lazy Loading of Blogger Images
It is necessary to confirm whether lazy loading of blogger images is working or not. There are many ways to do so. Either you can compare the page performance on GTMetrix with/without lazy loading or you can take the support of Inspect Element Feature present in web browsers.
- Navigate to the page where you have implemented lazy loading.
- Right click on empty space and select "Inspect Element".
- Select the Network Tab and Refresh the page.
- Scroll down and you should be able to see images getting loaded one after another as soon as you reach their viewport. Here is a small sample on how it looks:
The images are loaded once they are in the viewing region. This is called lazy loading of images.
You can also use LightHouse Chrome Extension to test if lazy loading is working efficiently or not.
- Add the lighthouse extension to your chrome browser.
- It will be added to the right of address bar.
- Navigate to the page you want to verify.
- Run the Light house test and you should be able to pass "Defer Offscreen Images" test.
Here is a detailed article on how to use chrome Lighthouse extension.
That's all. You have successfully implemented lazy loading of images in blogger and verified if it is working or not. Lazy loading of images improved our pagescore drastically. Now, its your turn. Happy blogging.
Here are a few handpicked tutorials for you to read next:
Show last Updated date in blogger posts along with published date
How to know if a website is on Wordpress or not
Killer SEO Guides to follow in 2019 for higher ranking
Attractive 404 Error Page Design For Blogger
Sign up for The Best Bits
Get all of our posts, straight to your email. Opt-out any time.
Not into email list things, but still want to read more?