Right now it seems like if we want to inject some content from a sub request we would use an async handler like so:
async element(e) {
const response = await fetch(url); // make sub request
const text = await response.text(); // whole text buffered in memor, this blocks from sending more data until we get full response
e.append(text); // insert text into main content
}
But isn't this sort of wasteful a bit, I mean we are needing to buffer the whole subrequest in memory and need to wait for the whole response to finish.
Wouldn't it be better if the rewritter would support something like this:
async element(e) {
const response = await fetch(url); // make sub request
e.append(response.body); // if stream provided it is correctly injected and streamed
}
In this case we will be returning the sub requests chunks as soon as they come and won't buffer them fully in memory.
Right now it seems like if we want to inject some content from a sub request we would use an async handler like so:
But isn't this sort of wasteful a bit, I mean we are needing to buffer the whole subrequest in memory and need to wait for the whole response to finish.
Wouldn't it be better if the rewritter would support something like this:
In this case we will be returning the sub requests chunks as soon as they come and won't buffer them fully in memory.