Let's suppose I have HTML template file containing such string:
<p> >>LEFT PART<< {{Data}} >>RIGHT PART<< </p>
Let's suppose both left and right part of this string dont contain nothing like
{{Data}}
, and I want to implement a function which takes this file and object like {Data:"My nice data",Name:"Sebastian"}
and returns file containing
<p> >>LEFT PART<< My nice data >>RIGHT PART<< </p>
instead. It's easy to do it by using string.prototype.replace actually. But now I have couple of questions:
- How do JS template engines perform similar tasks? In order to make my question certain and concrete lets say I'm talking about Jade, but you can describe another engine/framework like Pug, Dot etc.. Do they use Regular Expressions or some tricky algorithms searching for a substring?
- Will I lose perceptible execution speed if I use Regular Expressions and both left and right parts of my string contain ~10000 letters? Or html file contains 100+ lines of code.
P.S. I googled these questions, but most answers describe how to render page by using framework/engine, not how they do it.