What is the most scalable way to do large-scale search-replace operations in JavaScript?
I have an use case where I need to dynamically highlight 100+ words but it will scale bigger (e.g. possibly 1000+) within specific DIV fields of a large mostly text-only pages. Essentially adding custom CSS/HTML mouse-over highlighting to all ~100+ specific words. From a dynamically-changing list of potentially user-supplied words. On long pieces of user-submitted texts (aka forum).
I can do it either client-side (JS) or services-side (PHP), but I'm currently experimenting with client-side to keep web server load low.
RELATED: How to search for multiple texts in a string, using java script?
Except it's a search-replace performance scalability consideration for me.
In extreme scalability cases, I may eventually need to scan for 1000+ separate words on 100K of text (totalled, within between 10 to 100 div tags). At any time, only some (e.g. just 10 or 20% match) but there may be a search list of 1000+ words.
- Use a loop to search for each keyword one at a time, and apply CSS iteratively.
- Programmatically generate a complex regular expression that does it all in one pass.
- Another technique
Which historically perform faster overall -- given the widest range of browsers on the widest range of platforms?