|
1 | 1 | --- |
2 | | -title: Rewrite HTML with streaming content |
| 2 | +title: Transform HTML quickly with streaming content |
3 | 3 | description: HTMLRewiter now supports streamed content for more efficient replacement of HTML elements |
4 | 4 | products: |
5 | 5 | - workers |
6 | | -date: 2025-01-31T10:00:00Z |
| 6 | +date: 2025-01-31T01:00:00Z |
7 | 7 | --- |
8 | 8 |
|
9 | 9 | import { Render, TypeScriptExample } from "~/components"; |
10 | 10 |
|
11 | | -[`HTMLRewriter`](/workers/runtime-apis/html-rewriter) now supports replacing HTML with content from a stream. |
12 | | -[`Response`](/workers/runtime-apis/response/) and [`ReadableStream`](/workers/runtime-apis/streams/readablestream/) values can now |
13 | | -be passed as [`Content`](/workers/runtime-apis/html-rewriter/#global-types) into methods duch as |
14 | | -`replace`, `append`, and `prepend`. |
| 11 | +You can now transform HTML elements with streamed content using [`HTMLRewriter`](/workers/runtime-apis/html-rewriter). |
15 | 12 |
|
16 | | -This allows you to process HTML more efficiently, as content does not have to be loaded into memory before replacements are made. |
| 13 | +Methods like `replace`, `append`, and `prepend` now accept [`Response`](/workers/runtime-apis/response/) and [`ReadableStream`](/workers/runtime-apis/streams/readablestream/) |
| 14 | +values as [`Content`](/workers/runtime-apis/html-rewriter/#global-types). |
| 15 | + |
| 16 | +This can be helpful in a variety of situations. For instance, you may have a Worker in front of an origin, |
| 17 | +and want to replace an element with content from a different source. Prior to this change, if you wanted |
| 18 | +to replace an element with content from an upstream URL, you would have to load all of the content and convert |
| 19 | +it into a string before replacing the element. This slowed down overall response times. |
| 20 | + |
| 21 | +Now, you can pass the `Response` object directly into the `replace` method, and HTMLRewriter will immediately |
| 22 | +start replacing the content as it is streamed in. This makes responses faster. |
17 | 23 |
|
18 | 24 | <TypeScriptExample filename="index.ts"> |
19 | 25 | ```ts |
|
0 commit comments