How do you lazy load images in Angular and Ionic?

← Ionic answers

Add loading="lazy" to the <img> tag, or use Ionic's <ion-img>, which loads the image only when it scrolls into view.

<!-- Native browser lazy loading -->
<img src="assets/photo.jpg" loading="lazy" width="320" height="240" alt="Photo" />
 
<!-- Ionic component: loads when it enters the viewport -->
<ion-img src="assets/photo.jpg" alt="Photo"></ion-img>
 
<!-- Angular's optimized image directive: lazy by default, set priority for the hero image -->
<img ngSrc="assets/photo.jpg" width="320" height="240" alt="Photo" />
  • Always set width and height (or use CSS aspect-ratio) so the layout does not jump when the image appears.
  • Do not lazy load images that are visible on first paint; it delays them.
  • Inside ion-content lists, ion-img works well because it observes the scrolling container.
  • For custom behavior, an IntersectionObserver in a small directive can set src when the element becomes visible.

Related questions

Start debugging smarter today

Try Bugsee for free — no commitments, no hidden fees.

Free sign upLive demoNo credit card required