Hacker News new | ask | show | jobs
by twhb 2824 days ago
Using DOMParser means parsing the template twice, once for DOMParser and once for your template syntax, making perf gains more questionable. Also, doing HTML and template parsing separately means either passing template syntax through the HTML parser, which limits possible template syntax and spends time instantiating bogus DOM elements/attributes, or passing HTML through a HTML-unaware templating language, creating all the problems and limitations of C’s #define and making it hard to react to data changes with minimal updates.

That said, it’s been done both ways. Mustache templates do string templating then use the native HTML parser, and one smaller library, I don’t remember which, parses the template as HTML then tree walks for templating controls, and cites perf benefits.