I'm trying to send multiple chunks of data to a client each of which is rendered by Jade templating engine in Express Node.js framework.
- I have several views like header, viewA, viewB, viewC, etc.
- For every request I need to render the header partial view and send it as a chunk so that the client browser starts rendering it. When the header view is rendered I don't want the
<body>
tag inside to be closed, because more data is to come which should be inside the<body>
tag. - In the meantime, I need to do some computations and after that render another view: either A, B, or C.
- Once A, B, or C view is sent, I close the response which means closing the
</body></html>
tags.
Sounds very simple. But the problem is that Jade closes the <html>
and <body>
tags when rendering the header view.
I know how to do this manually using native Node.js response object, however, can't figure out how to do this with Jade the right way.
The only solution I currently see is to manually send the header part down to open <body>
tag, then render the rest as Jade partials via res.partial()
.
Any hint is highly appreciated.