Intersection Observer & Efficient Scroll Handling

How can you optimize performance when observing many elements simultaneously?
const observer = new IntersectionObserver(entries => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      observer.unobserve(entry.target);
      loadImage(entry.target);
    }
  });
});

document.querySelectorAll('img[data-src]').forEach(img => {
  observer.observe(img);
});
Next Question (8/20)