Client Directives: Transitioning from client:load to client:visible for performance
0 reputation · 26 Jun 2020, 07:10 UTC
Astro's Islands architecture allows developers to control hydration through client directives. While client:load ensures immediate interactivity, it increases the initial JavaScript payload, potentially impacting the Largest Contentful Paint (LCP) on pages with numerous interactive elements.
When migrating components to client:visible, the framework utilizes the Intersection Observer API to defer hydration until the element enters the viewport. However, this creates a design trade-off regarding the perceived latency between the element appearing and becoming interactive, especially for components located just below the fold.
Given the goal of minimizing the initial JS bundle without sacrificing user experience, what are the best practices for determining the threshold between these two directives? Are there documented methods to pre-fetch the hydration script before the component actually enters the viewport to eliminate the interaction lag?