Skip to main content
Hono’s JSX streaming allows you to send HTML to the client progressively, improving perceived performance by showing content as it becomes available. This is especially useful for pages with slow data fetching.

What is Streaming?

Streaming HTML means sending parts of the page to the browser before the entire page is ready. This allows:
  • Faster initial render - Show content immediately
  • Better perceived performance - Users see progress
  • Improved UX - No blank page while waiting
  • Efficient resource usage - Start rendering before all data loads
Streaming is an experimental feature. The API may change in future versions.

Basic Streaming

Use renderToReadableStream() to stream JSX content:
Source: src/jsx/streaming.ts:142-216

Suspense Component

The Suspense component allows you to show a fallback while async content loads:
Source: src/jsx/streaming.ts:42-133

How Suspense Works

When you use Suspense:
  1. The fallback is rendered immediately and sent to the client
  2. The async component starts loading in the background
  3. Once loaded, the actual content is sent to the client
  4. Client-side JavaScript replaces the fallback with the real content

Multiple Suspense Boundaries

You can have multiple Suspense boundaries for independent loading states:

Nested Suspense

Suspense boundaries can be nested:

StreamingContext

Use StreamingContext to configure streaming behavior, such as adding a nonce for CSP:
Source: src/jsx/streaming.ts:18-32

Error Handling

Handle errors in streaming with a custom error handler:
The error handler receives the error and can return HTML to display:
Source: src/jsx/streaming.ts:144

Async Components

Any component can be async when used with Suspense:

Promise Resolution

Suspense automatically handles promises in the component tree:

Streaming with the Stream Helper

Combine with Hono’s streaming helper for more control:

Performance Considerations

Wrap components that fetch data or perform expensive operations in Suspense boundaries.
Provide informative fallbacks that match the content shape.
Structure your page so critical content loads first.
Streaming is most beneficial on slower networks. On fast connections, the difference may be negligible.

Real-World Example: Product Page

Browser Compatibility

Streaming works in all modern browsers. The generated JavaScript for replacing fallbacks is minimal and works without any external dependencies.

Limitations

  • Streaming is experimental and the API may change
  • Error boundaries inside Suspense may have unexpected behavior
  • Some CDN/proxy configurations may buffer responses, negating streaming benefits
  • Client-side JavaScript is required for content replacement

Next Steps

Server Rendering

Learn about standard server-side rendering

DOM Rendering

Build interactive UIs with client-side rendering

JSX Overview

Back to JSX overview

Streaming Helper

Learn about the streaming helper