Skip to content

Partial Hydration

Key idea:

Partial Hydration — rendering optimisation: instead of loading + hydrating the entire React app, hydrate only components that need client-side interactivity. Zero JS for static read-only blocks. Implementations: Islands (Astro), RSC (Next.js), Resumability (Qwik), Progressive Hydration (Marko).

Below: details, example, related terms, FAQ.

Check your site →

Details

  • Traditional SSR: HTML + full JS bundle → client hydrates everything
  • Partial: HTML + small JS bundle → hydrate only flagged components
  • Savings: 60-95% JS reduction for typical blog/docs site
  • Trade-off: more complex framework, needs explicit interactivity markers
  • Metrics: TTI (time to interactive), TBT (total blocking time) drop dramatically

Example

// Astro — client directives
<StaticHero />                    {/* zero JS */}
<LikeButton client:load />        {/* hydrate immediately */}
<Comments client:visible />       {/* hydrate when scrolled to */}
<CartModal client:media="(max-width: 768px)" />  {/* mobile only */}

Related Terms

Understanding Partial Hydration

Partial hydration is an advanced rendering optimization technique used in modern web development to enhance performance and reduce the amount of JavaScript that needs to be executed on the client side. Instead of fully hydrating the entire React application on the client, partial hydration focuses on selectively hydrating only those components that require client-side interactivity. This approach is particularly beneficial for applications with a mix of static content and dynamic components, as it allows developers to minimize the JavaScript footprint and improve load times.

In a typical hydration process, the server sends fully rendered HTML to the client, which then 'hydrates' the components by attaching event listeners and enabling interactivity. With partial hydration, developers can identify which components are interactive and only hydrate those, leaving static blocks untouched. This leads to faster initial rendering and a better user experience, especially on slower networks or devices.

Several frameworks have adopted this concept, employing different implementations to achieve partial hydration:

  • Islands Architecture (Astro): Focuses on rendering static content first and only hydrates interactive components as needed.
  • React Server Components (RSC, Next.js): Allows developers to specify which components are server-rendered and which require client-side hydration.
  • Resumability (Qwik): Enables applications to resume execution from the server-rendered state without full rehydration.
  • Progressive Hydration (Marko): Hydrates components progressively based on user interaction and viewport visibility.

Implementing Partial Hydration in Your Project

To implement partial hydration in your project, you can leverage specific frameworks and libraries that support this technique. Below are examples of how to set up partial hydration using popular tools like Astro and Next.js.

Using Astro:

import { defineConfig } from 'astro/config'; import { partialHydration } from 'astro-partial-hydration'; export default defineConfig({ integrations: [partialHydration()], });

In your Astro component, you can define interactive elements as follows:

<!-- Component.astro --> <script type="module" client:only="interactive"> import InteractiveComponent from '../components/InteractiveComponent.astro'; export default InteractiveComponent;</script> <div>Static Content Here</div>

Using Next.js with React Server Components:

import { useEffect } from 'react'; const MyComponent = async () => { return <div>Server Rendered Content</div>; }; export default function Page() { return <MyComponent />; }

In this setup, ensure that only the components requiring client-side rendering are marked for hydration. This selective approach significantly optimizes performance by reducing the amount of JavaScript loaded and executed.

Benefits and Challenges of Partial Hydration

Partial hydration offers several benefits, but also comes with its own set of challenges that developers must consider when implementing it in their applications.

Benefits:

  • Improved Performance: By only hydrating the necessary components, partial hydration reduces the overall JavaScript bundle size, leading to faster loading times and improved performance, especially on mobile devices.
  • Enhanced User Experience: Users can interact with the application sooner, as static content is displayed immediately while interactive elements load in the background.
  • Better Resource Management: This approach allows developers to allocate resources more efficiently, as only essential scripts are executed, which can save bandwidth and processing power.

Challenges:

  • Complexity in Implementation: Implementing partial hydration can introduce complexity in the codebase, requiring developers to carefully manage which components are hydrated and when.
  • Framework Limitations: Not all frameworks support partial hydration out of the box, and some may require additional configuration or third-party libraries to achieve this functionality.
  • SEO Considerations: Developers must ensure that search engines can crawl and index the content properly, as excessive reliance on client-side rendering could affect SEO negatively.

Overall, while partial hydration can greatly enhance performance and user experience, it is essential to weigh these benefits against the potential challenges to determine if it is the right approach for your project.

Learn more

Frequently Asked Questions

Why is SPA hydration a problem?

You download 200 KB React + 50 KB your code, execute it all, re-render server HTML. TBT huge on mobile.

Qwik resumability?

Instead of hydration — serialise closures in HTML attributes, lazy-load on event. Zero initial JS for complex apps.

How to measure?

Lighthouse Speed Index + TBT. Partial hydration cuts from 3s → 0.3s on a typical blog.

Try the live tool that powered this guide

Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.