Skip to content

Streaming support #396

@harlan-zw

Description

@harlan-zw

Describe the feature

Related: #27

Most SSR js frameworks are streamable, we should support the same functionality with Unhead.

There is workarounds available but we should have an official solution that is documented.

Solving the Head Issue in Streaming HTML with Unhead

The Problem

Streaming HTML is sending content to the browser as it's created rather than waiting for the entire page to be ready. This approach has significant benefits:

  • Faster time to first byte
  • Lower server memory overhead
  • Progressive browser rendering
  • Better user experience with visible progress

However, there's a core challenge with the <head> section:

  1. The <head> needs to be sent early in the response
  2. Many <head> elements (like <title>) depend on data that isn't immediately available
  3. Waiting for this data defeats the purpose of streaming

Out-of-Order Streaming: The Solution

Instead of blocking the entire stream waiting for <head> data, we can use an approach called "out-of-order streaming":

  1. Stream a placeholder <head> immediately
  2. Continue streaming the rest of the page
  3. Update the <head> content later when data becomes available

Additional information

  • Would you be willing to help implement this feature?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions