Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: inject streams into streams #12

Open
vstefanovic97 opened this issue Jan 3, 2025 · 1 comment
Open

Feature request: inject streams into streams #12

vstefanovic97 opened this issue Jan 3, 2025 · 1 comment

Comments

@vstefanovic97
Copy link

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.

@jrestall
Copy link

lol-html recently added support for this btw cloudflare/lol-html#229

I don't think any of the wasm wrapper packages have been updated to support it though. workerd updated their implementation to use it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants