Overview - client:visible for viewport-based loading
What is it?
client:visible is a special directive in Astro that delays loading and running a component's JavaScript until the component scrolls into the user's visible area on the screen, called the viewport. This means the component only becomes active when the user can actually see it. It helps make websites faster by not loading unnecessary code right away.
Why it matters
Without client:visible, all interactive parts of a webpage load their JavaScript immediately, even if the user never scrolls to them. This slows down page loading and wastes data and battery. Using client:visible improves user experience by speeding up initial load times and saving resources, especially on slower devices or networks.
Where it fits
Before learning client:visible, you should understand basic Astro components and how client directives like client:load or client:idle work. After mastering client:visible, you can explore advanced performance techniques like partial hydration and intersection observers for lazy loading.