Middle+
There is a main page with many blocks and image cards. How to optimize performance (FPS, smooth scrolling)?
sobes.tech AI
Answer from AI
To optimize the performance of the main page with many blocks and images, it is recommended to:
- Use lazy loading for images to load them only when approaching the viewport.
- Optimize image sizes and formats (e.g., WebP instead of JPEG/PNG).
- Apply list virtualization (windowing) — render only the cards visible to the user in the DOM.
- Minimize re-renders and reflows, avoid heavy operations in scroll handlers.
- Use CSS properties that do not trigger layout recalculations (transform, opacity) for animations.
- Cache resources and use CDN for fast content delivery.
Example of lazy loading in React using Intersection Observer:
function LazyImage({ src, alt }) {
const [visible, setVisible] = React.useState(false);
const imgRef = React.useRef();
React.useEffect(() => {
const observer = new IntersectionObserver(
([entry]) => {
if (entry.isIntersecting) {
setVisible(true);
observer.disconnect();
}
},
{ threshold: 0.1 }
);
observer.observe(imgRef.current);
return () => observer.disconnect();
}, []);
return <img ref={imgRef} src={visible ? src : ''} alt={alt} />;
}