unjs / unhead

Unhead is the any-framework document head manager built for performance and delightful developer experience.
https://unhead.unjs.io
MIT License
639 stars 41 forks source link

Streaming support #396

Open harlan-zw opened 2 months ago

harlan-zw commented 2 months ago

Describe the feature

Related: https://github.com/unjs/unhead/issues/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.

Additional information

negezor commented 2 months ago

The problem is that the whole application has to be pre-processed. Since we can't know what hooks/components will be called. The DOM elements themselves can only be inserted at the end of <body> or make a buffer to insert in <head>, which makes no sense in streaming. However, many web crawlers do not look beyond </head>, which makes SSR meaningless for SEO.

harlan-zw commented 2 months ago

Yes, the idea is most likely a sync API for v2 that does not support hooks. I need to investigate it more but I believe we could just push the raw tags as json and resolve them client-side.

The exact use case for this is a bit niche though and needs some more thought.