SlideShare a Scribd company logo
Lazy Loading Website Assets
A Technique to Improve Your Page Speed
https://love2dev.com/blog/lazy-loading/
https://twitter.com/CHrisLove
https:./facebook.com/Love2Dev/
https://www.linkedin.com/company/love2dev/
Chris Love
Progressive Web
Apps and SEO
Specialist
Website speed is a crucial aspect of on page SEO everyone can
control. Your goal is to be interactive in under 3 seconds, even
on a basic phone over a 3G connection.
However, most web sites have so many requests and large
payloads this time limit or budget cannot be achieved. In fact, the
average web page takes 22 seconds to load, according to
Google's research.
Why Lazy Load
Website Speed
• Lazy-Load Content Scenarios
• What is IntersectionObever?
• Pagination/Continuous Scroll
• Using the History API
• Loading Scripts As Needed
Lazy-Load Content Scenarios
For simplicity I will just call it a blog. These sites
typically need HTML, CSS, JavaScript, images
and custom fonts. They also tend to be sites you
want free organic traffic from Google, which
means SEO is important.
Content Focused Sites
Complex web applications can be a little more
delicate because they lean on more application
logic. This means they require more JavaScript
files. When these files are loaded matters. While
you can use IntersectionObserver for this, your
application needs a good technique to
dynamically load scripts as needed.
Web Apps
Images require bandwidth and may not even be seen. Deferring
their request means you can prioritize other content, like HTML
and CSS.
Just make sure the images are available to Google.
The noscript tag is a semantic mechanism to tell the browser to
only render the content inside the element if the browser (user
agent) does not support JavaScript. Most visitors will have
JavaScript turned on, so they won't trigger the image to load
initially. But as you will shortly see it will when the non-noscript
image is visible.
Lazy Load Images
Image here
Your Business
Example Code
<img data-srcset="img/example-869x361.jpg 869w, ..."
data-src="img/example-869x361.jpg" class="lazy-image"
sizes="(max-width: 480px) 90vw, 30vw" alt=“…">
<noscript><img src="img/example-869x361.jpg"
alt=“…"></noscript>
Lazy Load Images
The images are not requested
until the data-src and data-srcset
attributes are converted to the
normal src and srcset attributes.
This is done using
IntersectionObserver.
Image here
What is IntersectionObserver?
Triggers a callback when target elements come into view.
How it Works
Supported by all modern browsers and there is a stable polyfil
you can dynamically load for those that don't.
Browser Support
IntersectionObserver
This API triggers a callback when target elements come into
view. This callback allows you to execute code, which in our
scenario is to load assets as needed.
Load as It Enters
Viewport
As observed content approaches the visible viewport the
IntersectionObserver API triggers a callback method. Inside this
method you can execute code to update and load assets on
demand.
Example Code
var config = {
// If the image gets within 50px in the Y axis, start the
download.
rootMargin: '50px 0px',
threshold: 0.1
};
imgObserver = new IntersectionObserver(showImage, config);
imgObserver.observe(yourImage);
Pagination /
Continuous Scroll
A common tactic on news related sites in the past couple of years.
This is where you scroll down an article and as you reach the bottom
a new article is rendered.
Solutions:
• IntersectionObserver
• History API
Using the History API
The main advantage it provides is the ability to
change the URL in the address bar without
triggering a server request that causes a
complete page reload. It works much like the
hash fragment technique, but uses a shareable
URL.
Web Apps
Loading Scripts As Needed
JavaScript is the single biggest cause of poor
page render times. By offloading scripts you
remove them from the rendering process.
Improves Page Load
Create a script element for each script and
appending it to the DOM. Once appended the
browser loads the script just as if it were part of
the initial markup.
Add Scripts on Demand
Requires a little finesse, but can make your UX
so much better, which should improve customer
satisfaction and retention while reducing help
desk calls.
Complex Web Apps
Load minimal script footprint. Gets application
going.
Boot Up Experience
300 x 50 px
Thank you!
Love2Dev

More Related Content

What's hot (20)

PDF
A Simpler Web App Architecture (jDays 2016)
Gustaf Nilsson Kotte
 
PPTX
10 things you can do to speed up your web app today 2016
Chris Love
 
PDF
Introduction core web vitals
SortdMediology
 
PPTX
Develop a vanilla.js spa you and your customers will love
Chris Love
 
PPTX
Pros and Cons of developing a Thick Clientside App
Ravi Teja
 
PPTX
DeepCrawl Webinar: Performing SEO on the Edge
Dan Taylor
 
PPTX
Single page application
Arthur Fung
 
PPT
Website speed optimization techniques
ValueCoders
 
PPTX
JavaScript front end performance optimizations
Chris Love
 
PPTX
Core web vitals is the thing you should focus on if you own a website in 2021
World Web Technology Pvt Ltd
 
PPTX
Advanced front end debugging with ms edge and ms tools
Chris Love
 
PDF
How i acheived a pretty good google page speed insights score
Matt Bailey
 
PDF
Core Web Vitals Optimization for any website, especially WordPress
ClementYo
 
PDF
Prioritize your critical css and images to render your site fast velocity ny...
Jan-Willem Maessen
 
PDF
Server rendering-talk
Daiwei Lu
 
PDF
Web Performance & Operation - Pagespeed
draskolnikova
 
PPTX
Performace optimization (increase website speed)
clickramanm
 
PDF
Website speed optimization guide for technically advanced webmasters
Aditya Singh
 
PPTX
Implementing a Responsive Image Strategy
Chris Love
 
PPTX
BrightonSEO 2019 - Edge SEO - Using CDNs To Perform SEO On The Edge
Dan Taylor
 
A Simpler Web App Architecture (jDays 2016)
Gustaf Nilsson Kotte
 
10 things you can do to speed up your web app today 2016
Chris Love
 
Introduction core web vitals
SortdMediology
 
Develop a vanilla.js spa you and your customers will love
Chris Love
 
Pros and Cons of developing a Thick Clientside App
Ravi Teja
 
DeepCrawl Webinar: Performing SEO on the Edge
Dan Taylor
 
Single page application
Arthur Fung
 
Website speed optimization techniques
ValueCoders
 
JavaScript front end performance optimizations
Chris Love
 
Core web vitals is the thing you should focus on if you own a website in 2021
World Web Technology Pvt Ltd
 
Advanced front end debugging with ms edge and ms tools
Chris Love
 
How i acheived a pretty good google page speed insights score
Matt Bailey
 
Core Web Vitals Optimization for any website, especially WordPress
ClementYo
 
Prioritize your critical css and images to render your site fast velocity ny...
Jan-Willem Maessen
 
Server rendering-talk
Daiwei Lu
 
Web Performance & Operation - Pagespeed
draskolnikova
 
Performace optimization (increase website speed)
clickramanm
 
Website speed optimization guide for technically advanced webmasters
Aditya Singh
 
Implementing a Responsive Image Strategy
Chris Love
 
BrightonSEO 2019 - Edge SEO - Using CDNs To Perform SEO On The Edge
Dan Taylor
 

Similar to Lazy load Website Assets (20)

PDF
Web Performance in the Age of HTTP2 - Topconf Tallinn 2016 - Holger Bartel
Holger Bartel
 
PDF
Building performance into the new yahoo homepage presentation
masudakram
 
PDF
Performance on the Yahoo! Homepage
Nicholas Zakas
 
PDF
WebsitePerformance
Vivek Jain
 
PPTX
Web Directions South - Even Faster Web Sites
Steve Souders
 
PPTX
High-Speed HTML5
Peter Lubbers
 
PDF
Hacking Web Performance 2019
Maximiliano Firtman
 
KEY
Faster Frontends
Andy Davies
 
PDF
Front end-performance
Prajwala Manchikatla
 
PDF
A little journey into website optimization
Stelian Firez
 
PDF
Web Performance Optimization (WPO)
Betclic Everest Group Tech Team
 
PPTX
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
Distilled
 
PDF
2013 10-02-html5-performance-aarhus
SC5.io
 
PPT
After YSlow "A"
Nicole Sullivan
 
PDF
Front-end optimisation & jQuery Internals
Artur Cistov
 
PPTX
Drupal Frontend Performance and Scalability
Ashok Modi
 
PPTX
Website Performance
Hugo Fonseca
 
PDF
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
Andy Davies
 
PDF
Velocity_Conference
Anne Cypcar
 
PDF
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
Bastian Grimm
 
Web Performance in the Age of HTTP2 - Topconf Tallinn 2016 - Holger Bartel
Holger Bartel
 
Building performance into the new yahoo homepage presentation
masudakram
 
Performance on the Yahoo! Homepage
Nicholas Zakas
 
WebsitePerformance
Vivek Jain
 
Web Directions South - Even Faster Web Sites
Steve Souders
 
High-Speed HTML5
Peter Lubbers
 
Hacking Web Performance 2019
Maximiliano Firtman
 
Faster Frontends
Andy Davies
 
Front end-performance
Prajwala Manchikatla
 
A little journey into website optimization
Stelian Firez
 
Web Performance Optimization (WPO)
Betclic Everest Group Tech Team
 
SearchLove San Diego 2018 | Mat Clayton | Site Speed for Digital Marketers
Distilled
 
2013 10-02-html5-performance-aarhus
SC5.io
 
After YSlow "A"
Nicole Sullivan
 
Front-end optimisation & jQuery Internals
Artur Cistov
 
Drupal Frontend Performance and Scalability
Ashok Modi
 
Website Performance
Hugo Fonseca
 
Are Today’s Good Practices… Tomorrow’s Performance Anti-Patterns?
Andy Davies
 
Velocity_Conference
Anne Cypcar
 
The Need for Speed (5 Performance Optimization Tipps) - brightonSEO 2014
Bastian Grimm
 
Ad

More from Chris Love (20)

PPTX
Quick Fetch API Introduction
Chris Love
 
PPTX
Introduction to Progressive Web Applications
Chris Love
 
PPTX
Introduction to Progressive Web Applications
Chris Love
 
PPTX
Progressive Web Apps for Education
Chris Love
 
PPTX
The server is dead going serverless to create a highly scalable application y...
Chris Love
 
PPTX
A Day Building Fast, Responsive, Extensible Single Page Applications
Chris Love
 
PPTX
Real World Lessons in Progressive Web Application & Service Worker Caching
Chris Love
 
PPTX
Disrupting the application eco system with progressive web applications
Chris Love
 
PPTX
Using Responsive Web Design To Make Your Web Work Everywhere - Updated
Chris Love
 
PPTX
Using Responsive Web Design To Make Your Web Work Everywhere
Chris Love
 
PPT
Css best practices style guide and tips
Chris Love
 
PPTX
Using Responsive Web Design To Make Your Web Work Everywhere
Chris Love
 
PPTX
An Introduction to Microsoft Edge
Chris Love
 
PPTX
10 things you can do to speed up your web app today stir trek edition
Chris Love
 
PPTX
Single page applications the basics
Chris Love
 
PPTX
There Is No Mobile: An Introduction To Responsive Web Design
Chris Love
 
PPTX
Touch the web
Chris Love
 
PPTX
10 Things You Can Do to Speed Up Your Web App Today
Chris Love
 
PPTX
SPAs Are Easy
Chris Love
 
PPTX
A night at the spa
Chris Love
 
Quick Fetch API Introduction
Chris Love
 
Introduction to Progressive Web Applications
Chris Love
 
Introduction to Progressive Web Applications
Chris Love
 
Progressive Web Apps for Education
Chris Love
 
The server is dead going serverless to create a highly scalable application y...
Chris Love
 
A Day Building Fast, Responsive, Extensible Single Page Applications
Chris Love
 
Real World Lessons in Progressive Web Application & Service Worker Caching
Chris Love
 
Disrupting the application eco system with progressive web applications
Chris Love
 
Using Responsive Web Design To Make Your Web Work Everywhere - Updated
Chris Love
 
Using Responsive Web Design To Make Your Web Work Everywhere
Chris Love
 
Css best practices style guide and tips
Chris Love
 
Using Responsive Web Design To Make Your Web Work Everywhere
Chris Love
 
An Introduction to Microsoft Edge
Chris Love
 
10 things you can do to speed up your web app today stir trek edition
Chris Love
 
Single page applications the basics
Chris Love
 
There Is No Mobile: An Introduction To Responsive Web Design
Chris Love
 
Touch the web
Chris Love
 
10 Things You Can Do to Speed Up Your Web App Today
Chris Love
 
SPAs Are Easy
Chris Love
 
A night at the spa
Chris Love
 
Ad

Recently uploaded (20)

PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
July Patch Tuesday
Ivanti
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
July Patch Tuesday
Ivanti
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 

Lazy load Website Assets

  • 1. Lazy Loading Website Assets A Technique to Improve Your Page Speed https://love2dev.com/blog/lazy-loading/
  • 3. Website speed is a crucial aspect of on page SEO everyone can control. Your goal is to be interactive in under 3 seconds, even on a basic phone over a 3G connection. However, most web sites have so many requests and large payloads this time limit or budget cannot be achieved. In fact, the average web page takes 22 seconds to load, according to Google's research. Why Lazy Load Website Speed
  • 4. • Lazy-Load Content Scenarios • What is IntersectionObever? • Pagination/Continuous Scroll • Using the History API • Loading Scripts As Needed
  • 5. Lazy-Load Content Scenarios For simplicity I will just call it a blog. These sites typically need HTML, CSS, JavaScript, images and custom fonts. They also tend to be sites you want free organic traffic from Google, which means SEO is important. Content Focused Sites Complex web applications can be a little more delicate because they lean on more application logic. This means they require more JavaScript files. When these files are loaded matters. While you can use IntersectionObserver for this, your application needs a good technique to dynamically load scripts as needed. Web Apps
  • 6. Images require bandwidth and may not even be seen. Deferring their request means you can prioritize other content, like HTML and CSS. Just make sure the images are available to Google. The noscript tag is a semantic mechanism to tell the browser to only render the content inside the element if the browser (user agent) does not support JavaScript. Most visitors will have JavaScript turned on, so they won't trigger the image to load initially. But as you will shortly see it will when the non-noscript image is visible. Lazy Load Images Image here Your Business
  • 7. Example Code <img data-srcset="img/example-869x361.jpg 869w, ..." data-src="img/example-869x361.jpg" class="lazy-image" sizes="(max-width: 480px) 90vw, 30vw" alt=“…"> <noscript><img src="img/example-869x361.jpg" alt=“…"></noscript>
  • 8. Lazy Load Images The images are not requested until the data-src and data-srcset attributes are converted to the normal src and srcset attributes. This is done using IntersectionObserver. Image here
  • 9. What is IntersectionObserver? Triggers a callback when target elements come into view. How it Works Supported by all modern browsers and there is a stable polyfil you can dynamically load for those that don't. Browser Support
  • 10. IntersectionObserver This API triggers a callback when target elements come into view. This callback allows you to execute code, which in our scenario is to load assets as needed. Load as It Enters Viewport As observed content approaches the visible viewport the IntersectionObserver API triggers a callback method. Inside this method you can execute code to update and load assets on demand.
  • 11. Example Code var config = { // If the image gets within 50px in the Y axis, start the download. rootMargin: '50px 0px', threshold: 0.1 }; imgObserver = new IntersectionObserver(showImage, config); imgObserver.observe(yourImage);
  • 12. Pagination / Continuous Scroll A common tactic on news related sites in the past couple of years. This is where you scroll down an article and as you reach the bottom a new article is rendered. Solutions: • IntersectionObserver • History API
  • 13. Using the History API The main advantage it provides is the ability to change the URL in the address bar without triggering a server request that causes a complete page reload. It works much like the hash fragment technique, but uses a shareable URL.
  • 14. Web Apps Loading Scripts As Needed JavaScript is the single biggest cause of poor page render times. By offloading scripts you remove them from the rendering process. Improves Page Load Create a script element for each script and appending it to the DOM. Once appended the browser loads the script just as if it were part of the initial markup. Add Scripts on Demand Requires a little finesse, but can make your UX so much better, which should improve customer satisfaction and retention while reducing help desk calls. Complex Web Apps Load minimal script footprint. Gets application going. Boot Up Experience 300 x 50 px