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.