Next.js Discord

Discord Forum

Could Next.js app router return just a fragment of HTML ?

Unanswered
Saltwater Crocodile posted this in #help-forum
Open in Discord
Saltwater CrocodileOP
I have this unusual use case of web application, that need to return just a fragment of HTML, meaning the root element would be a <div>, without <html>,<head> or <body> tags.
The returned html would than be inserted into larger application, integrating different html chunks.
I wonder if this could be somehow possible using Next.js App router, maybe just tweaking the root layout ?
If its not possible, I would have to build custom solution or use just SPA, but I would love to be able to make this work with standard Next and RSC.
Thank you for the answers!

3 Replies

kinda. App Routern sends chunks as Wired Format if Suspense is used. web page is progressively rendered. you need to deploy to Edge Runtime, where it is billed based on CPU Time(not Wall-clock time) to leverage this mecanism though.
streaming is done over HTTP/2 or 1.1 chunks
obviously it works on self-hosted such as GCP as well.