Other differences in Handlebars from Mustache templates

Many of the features in Handlebars.js that differentiate it from Mustache.js are designed to make the templates render more quickly in a browser. One of the main features in Handlebars that allows this is the ability to precompile templates, as we covered in Chapter 2, Model-View-Whatever.

Precompiling templates

Precompiling the templates converts them to the JavaScript functions that are normally compiled in an application before rendering with other templating engines. Using this feature increases the speed of an application by skipping that step, and it additionally reduces the load on the browser for the application because the JavaScript compiler does not need to be included in the frontend asset payload.

No alternative delimiters

The creators of Handlebars also decided that the ability to set alternative delimiters within a template is not necessary. This further reduces the asset payload for an application if you are not precompiling your templates.

Usually, the only reason you would want to change the delimiter style for templates, other than personal preference, is to avoid conflicts with another templating language, for example, a server-side templating language that uses the same delimiters. If you were to include your Handlebars templates inside of JavaScript blocks within a server-side template, this issue would materialize. If you precompile your templates or abstract them from your server-side templates by keeping them in their own external JavaScript files, however, that issue can be avoided entirely and there is no need to set alternative delimiters.

You can learn more about Handlebars.js at handlbarsjs.com.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.140.68