P
P
Pavel2016-02-09 19:01:12
JavaScript
Pavel, 2016-02-09 19:01:12

What is the best way to deal with the template engine in lodash (performance question)?

I am using lodash templating engine in a project. Lodash is simple and not logic-less like mustache. It may not be the best idea to transfer logic to templates, but at this stage, under the current conditions, there is no way to take and rewrite.
Now it works like this: there is a large json containing data. The data has its own key, which determines how it should be rendered. Depending on this key, certain tags with one or another hierarchy are written in the template.
How much slower will it be if each specific subpattern is in a separate file?
That is, the first option is this:
In js, we take json, give it to the template. In the template check

<% if (key='table') { %>
<table>...</table>
<% } if (key ='supertable')  { %>
<image><table class="superpuper">... </table><div class="bottom">
<% }  if (key ='imageBlock')  { %>
<div class="image"><img></div>
<% } %>

Whereas the second option is this:
In js, we call keyour own template for a certain one, placing it in the place generated before.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2016-02-09
@alexey-m-ukolov

How much slower will it be if each specific subpattern is in a separate file?
If you have this template rendered less than a million times per second, the difference can be neglected. Well, if you don’t take a word, no one bothers to take and profile.

D
Dark Hole, 2016-02-09
@abyrkov

Almost no difference. Simply if in a separate file - a separate request is required. Not critical though

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question