简体   繁体   中英

Handlebars.js and link tags

I am learning about javascript templating engines and am looking to use handlebars.js .

From what I understand about handlebars.js, it is mainly used to minimalize content on a HTML page, more specifically things like

<h2>{{h2 title}}</h2>
<p>{{Paragraph information}}</p>

I thought that this was amazing, and would be great to use to minimalize the multiple script, link .css I have on a page.

However, on the handlebars page, I actually didn't see anything on it even though I thought that'd be an amazing use of it so I came to the conclusion that it's probably not what it's supposed to be used for?

So, my quesiton is...are there any downsides to doing so and should I use this approach to minimalize my <script> and <link> tags?

The first use of handlebars is to have : templates that are computed by the client ... and this is great to my mind if you want for example ajax content to be displayed on the client without having to resend a whole html page.

That means that yes you can reuse your code but your data will still have to be transmitted to the user and the "size" of data will not always be a gain.

But the aim of templates is the genericity of your code, so you'll don't bother what you'll display you have to get a code that display always the objects with the same method.

In my case I use it to display values on the clients without having to calculate the same html on the server. So the client load the page, and whenever he clicks on a value, I first get the JSON context that stick with my value and then I compute the result of the context + the template on the client browser to put it finally in the DOM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM