In detail
Hydration is a core concept in modern web frameworks like Next.js, Remix, and Astro. When a server renders a page, it sends static HTML to the browser for fast initial display. Hydration is the process where the framework's client-side JavaScript 'wakes up' this static HTML by attaching event listeners, restoring state, and making components interactive. Partial Hydration (used in Astro and React Server Components) optimizes this by only hydrating interactive components, leaving static content as plain HTML. This reduces JavaScript bundle size and improves Time to Interactive (TTI).
How it works
- 1
Server Render
The server generates complete HTML for the page, including all content and initial state.
- 2
HTML Delivery
The static HTML is sent to the browser, which displays it immediately (fast First Contentful Paint).
- 3
JavaScript Loading
The browser downloads and parses the JavaScript bundles needed for interactivity.
- 4
Event Attachment
React (or another framework) walks the DOM, attaches event listeners, and restores component state.
Where it is used
- SEO-Optimized SPAs
- Single-page applications that serve crawlable HTML to search engines while remaining fully interactive for users.
- Performance Optimization
- Using partial hydration to reduce JavaScript payloads and improve Core Web Vitals scores.
- Progressive Enhancement
- Pages that work as static HTML even before JavaScript loads, then progressively enhance with interactivity.