Client-Side Data Hydration
What you'll learn: How to enhance statically generated pages with fresh, personalized data loaded in the browser after the initial page renders.
The Core Idea
When you use SSG, your pages are built once at build time. This creates a challenge: what if you need real-time data like stock prices, user notifications, or personalized recommendations? Client-side data hydration solves this by delivering your static HTML first (fast!), then making API calls from the browser to fetch and inject dynamic data after the page loads.
Think of it like a newspaper that's printed overnight (static content) with a blank space reserved for today's weather. When you pick up the paper, someone fills in that weather box with the latest forecast (client-side hydration).
How It Works
Your static page loads instantly with all the core content already rendered. The browser then executes JavaScript that calls external APIs to fetch additional data. This data "hydrates" specific parts of your page—filling in comments, loading user profiles, displaying live inventory counts, or showing personalized recommendations.
This approach combines the best of both worlds: the speed and SEO benefits of static generation, plus the freshness of client-side rendering for data that must be current.
Common Use Cases
- Loading user-specific content (notifications, preferences)
- Displaying real-time inventory or pricing
- Fetching comments or reviews after page load
- Showing personalized recommendations
- Pulling in social media feeds or live data
The pattern lets you keep your build times fast even with massive sites, since you're not regenerating pages every time data changes—you're just updating specific components dynamically.
Key Takeaway: Client-side data hydration lets you start with fast, static HTML and enhance it with fresh API data, combining SSG's performance benefits with the dynamic capabilities you learned in CSR.