top | item 41017990

(no title)

sntran | 1 year ago

Cloudflare has a thing called HTMLRewriter that is both a streaming HTML parser and selector for changing it. It's very efficient and let you change only the places you need.

For your example, you can just match in `[id^="insert"]` and add the actual firstName value in the handler.

I use it alot on the server side, but it's for JavaScript side, or Rust if you use the lower level lol-html.

discuss

order

hawski|1 year ago

+1 to the lol_html HTML rewriter. Basically you can give it a bunch of selectors and code that will do whatever with what is matching. It's very fast and quite nice. It has bindings to Lua and a few more, but not to Python.

https://crates.io/crates/lol_html

throwitaway1123|1 year ago

The HTMLRewriter API is pleasant to work with. Bun has implemented it in addition to Cloudflare Workers. I would love for WinterCG to work on standardizing this API across JS runtimes so that I don't have to interact with lol-html across a WASM boundary in Node and Deno.