3 ms·
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 pl
by sntran 2y 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.
- throwitaway1123 2y agoThe 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.
- hawski 2y 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 https://crates.io/crates/lol_html