I have some Javascript that it dynamically creating some Javascript. Part of this is concatenating several thousand strings together, which is quite slow. What is the fastest way to build HTML dynamically in Javascript based upon a Json object.
1 Answer
If you want to build HTML out of a JSON object, a templating engine is what you need.
There are several out there, but make your choice based on your requirements, not on what people tell you is "the best".
If there's the possibility that you have to do asynchronous calls in the render process, you definitely should go for an asynchronous templating engine.
dust.js is one of those.
For sync use only, handlebars is a popular choice. It's quite fast, but it is intended to be very minimalistic. Meaning, the logic should mostly happen outside of the templates.
Maybe have a look at http://garann.github.io/template-chooser/ and pick one that suits your needs.
+. But there are tricks for working with the DOM.