Skip to main content

A module filter.

Lazy-load images

Images

Defers off-screen images until they scroll into the viewport.

Filter lazyload_images · Filter docs · Read the full guide

Both frames render identically — that's the goal. The win is in the bytes and requests below, not the look. They're served live by the mod_pagespeed module on demo-httpd-1.1.modpagespeed.com; the optimized frame applies only this filter. Right after a cache purge it may briefly match the original while the worker rewrites it — reload to see the result. mod_pagespeed applies this filter only for browsers it recognizes as supporting it, so the measurement requested the optimized page as a browser.

Measured impact

In this capture the HTML document grows from 964 B to 1.6 KB, and the total weight (HTML plus the files it loads) rises from 83.3 KB to 83.9 KB, 1% larger, so there's no byte or request reduction to chart. The change shows in the source diff below.

What changed in the source

The page's HTML, before and after this filter. Red lines are removed, green lines are added.

                
                  
… 1 unchanged line …
<head>
<title>lazyload_images example</title>
</head>
- <body>
+ <body><noscript><meta HTTP-EQUIV="refresh" content="0;url='https://demo-httpd-1.1.modpagespeed.com/mod_pagespeed_example/lazyload_images.html?PageSpeed=noscript'"/><style><!--table,div,span,font,p{display:none} --></style><div style="display:block">Please click <a href="https://demo-httpd-1.1.modpagespeed.com/mod_pagespeed_example/lazyload_images.html?PageSpeed=noscript">here</a> if you are not redirected within a few seconds.</div></noscript>
<p>*</p>
<p>*</p>
<p>*</p>
… 5 unchanged lines …
<p>*</p>
<p>*</p>
<p>*</p>
- <img src="images/BikeCrashIcn.png"><br/>
+ <img src="images/BikeCrashIcn.png" loading="lazy" decoding="async"><br/>
<p>*</p>
<p>*</p>
<p>*</p>
<p>*</p>
<p>*</p>
- <img src="images/BikeCrashIcn.png"><br/>
+ <img src="images/BikeCrashIcn.png" loading="lazy" decoding="async"><br/>
<p>*</p>
<p>*</p>
<p>*</p>
<p>*</p>
<p>*</p>
- <img src="images/BikeCrashIcn.png"><br/>
+ <img src="images/BikeCrashIcn.png" loading="lazy" decoding="async"><br/>
<p>*</p>
<p>*</p>
<p>*</p>
<p>*</p>
<p>*</p>
- <img src="images/BikeCrashIcn.png"><br/>
+ <img src="images/BikeCrashIcn.png" loading="lazy" decoding="async"><br/>
<p>*</p>
<p>*</p>
<p>Should be below the fold on most screens. The images below will only be
loaded once you scroll down.</p>
<p>*</p>
<p>*</p>
- <img src="images/Puzzle2.jpg" srcset="images/Puzzle.jpg 2x"><br/>
- <img src="images/IronChef2.gif"><br/>
- <img src="images/Cuppa.png"><br/>
+ <img src="images/Puzzle2.jpg" srcset="images/Puzzle.jpg 2x" loading="lazy" decoding="async"><br/>
+ <img src="images/IronChef2.gif" loading="lazy" decoding="async"><br/>
+ <img src="images/Cuppa.png" loading="lazy" decoding="async"><br/>
</body>
</html>

Run this on your own site

This is one of 49 filters the mod_pagespeed module applies in place — self-hosted on Apache, nginx, and IIS. Install and run it: it optimizes right away and adds the optimized response headers shown above. Open source under the Apache License 2.0 — free in development and in production.

Search