Need advice about which tool to choose?Ask the StackShare community!

Handlebars.js

7.8K
3.2K
+ 1
309
Underscore

1.7K
589
+ 1
290
Add tool

Handlebars.js vs Underscore: What are the differences?

Introduction

Handlebars.js and Underscore are both popular JavaScript libraries commonly used in web development. While they share some similarities, there are several key differences between the two that developers should be aware of. This Markdown code provides a brief comparison of Handlebars.js and Underscore, highlighting their main distinctions.

  1. Syntax and Templating: Handlebars.js is primarily a templating engine that allows for dynamic content rendering. It provides a simple and intuitive syntax, utilizing custom delimiters (such as {{}}) for injecting data into HTML templates. On the other hand, Underscore focuses more on manipulating and iterating over data with a functional programming approach, offering utilities like map, filter, and reduce functions.

  2. Template Rendering: Handlebars.js operates by taking a template and binding it to data, which can then be rendered as HTML. It excels at rendering complex templates with custom logic and partials, making it a popular choice for rendering dynamic content. In contrast, Underscore does not have built-in templating capabilities and is mainly used for data manipulation and transformation.

  3. Data Binding: Handlebars.js provides data binding functionality, where changes in the data are automatically reflected in the rendered views. This enables developers to create reactive interfaces without manually updating the DOM. Underscore, however, does not have built-in data binding capabilities, requiring developers to handle data updates manually.

  4. Compatibility: Handlebars.js can be used in both client-side and server-side environments, making it versatile for various development scenarios. It can be integrated with frameworks like Ember.js for enhanced functionality. Meanwhile, Underscore is primarily designed for client-side JavaScript and is commonly used as a utility library in conjunction with other frameworks or libraries.

  5. Dependencies: Handlebars.js has no external dependencies and can be used as a standalone library. It has its own template engine and does not rely on other external JavaScript libraries. On the other hand, Underscore has no dependencies on other libraries either and can be used independently.

  6. Size: Handlebars.js is relatively larger in size compared to Underscore. The minified version of Handlebars.js is around 16 KB, while Underscore's minified version is only about 5 KB. This size difference can be a factor when considering page load times and network bandwidth.

In summary, Handlebars.js specializes in templating and data binding, offering an intuitive syntax for rendering dynamic content, while Underscore focuses more on data manipulation and functional programming. Both libraries have their own strengths and use cases, depend on the specific requirements of the project.

Advice on Handlebars.js and Underscore
Asad Gilani
Software Engineer at Lisec Automation · | 5 upvotes · 203.4K views
Needs advice
on
Handlebars.jsHandlebars.js
and
LiquidLiquid

@All: I am searching for the best template engine for .NET. I started looking into several template engines, including the Dotliquid, Handlebars.js, Scriban, and Razorlight. I found handlebar a bit difficult to use when using the loops and condition because you need to register for helper first. DotLiquid and Scriban were easy to use and in Razorlight I did not find the example for loops.

Can you please suggest which template engine is best suited for the use of conditional/list and looping and why? Or if anybody could provide me a resource or link where I can compare which is best?

Thanks In Advance

See more
Replies (1)
Josh Lind
Recommends
on
Handlebars.jsHandlebars.js

I like Handlebars, it's very mature... some would say-- outdated.

Handlebars loops are done via {{#each myList}}. Read the docs! https://handlebarsjs.com/guide

Remember, don't put logic in your templates! Keep this layer simple. Sorry to hear you have to use dotNet.

See more
Decisions about Handlebars.js and Underscore

Fast Healthcare Interoperability Resources (FHIR) provides standard data objects in JSON format for the healthcare industry. Since JSON objects are hierarchical and tree-like, we had a need to defensively 'pluck' fields from our JSON objects and do lots of mapping. We tried jQuery and Underscore and a few other technologies like FHIRPath; but Lodash has been the most well supported, works in the most contexts, has the cleanest syntax, etc. We particularly like the ES6 version of Lodash, where we can import the method names directly, without resorting to * or _ syntax. We got hooked on the 'get' function to defensively pluck fields from objects without crashing our user interface, and have found countless uses for the other lodash functions throughout our apps. Lodash is great for developing and optimizing algorithms.

See more
Get Advice from developers at your company using StackShare Enterprise. Sign up for StackShare Enterprise.
Learn More
Pros of Handlebars.js
Pros of Underscore
  • 106
    Simple
  • 77
    Great templating language
  • 50
    Open source
  • 36
    Logicless
  • 20
    Integrates well into any codebase
  • 10
    Easy to create helper methods for complex scenarios
  • 7
    Created by Yehuda Katz
  • 2
    Easy For Fornt End Developers,learn backend
  • 1
    Awesome
  • 85
    Utility
  • 55
    Simple
  • 40
    Functional programming
  • 32
    Fast
  • 28
    Open source
  • 20
    Backbone
  • 16
    Javascript
  • 8
    Annotated source code
  • 6
    Library

Sign up to add or upvote prosMake informed product decisions

- No public GitHub repository available -

What is Handlebars.js?

Handlebars.js is an extension to the Mustache templating language created by Chris Wanstrath. Handlebars.js and Mustache are both logicless templating languages that keep the view and the code separated like we all know they should be.

What is Underscore?

A JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects.

Need advice about which tool to choose?Ask the StackShare community!

What companies use Handlebars.js?
What companies use Underscore?
See which teams inside your own company are using Handlebars.js or Underscore.
Sign up for StackShare EnterpriseLearn More

Sign up to get full access to all the companiesMake informed product decisions

What tools integrate with Handlebars.js?
What tools integrate with Underscore?

Blog Posts

What are some alternatives to Handlebars.js and Underscore?
AngularJS
AngularJS lets you write client-side web applications as if you had a smarter browser. It lets you use good old HTML (or HAML, Jade and friends!) as your template language and lets you extend HTML’s syntax to express your application’s components clearly and succinctly. It automatically synchronizes data from your UI (view) with your JavaScript objects (model) through 2-way data binding.
Mustache
Mustache is a logic-less template syntax. It can be used for HTML, config files, source code - anything. It works by expanding tags in a template using values provided in a hash or object. We call it "logic-less" because there are no if statements, else clauses, or for loops. Instead there are only tags. Some tags are replaced with a value, some nothing, and others a series of values.
React
Lots of people use React as the V in MVC. Since React makes no assumptions about the rest of your technology stack, it's easy to try it out on a small feature in an existing project.
doT.js
It is a fastest and concise javascript template engine for Node.js and browsers. It was created in search of the fastest and concise JavaScript templating function with emphasis on performance under V8 and Node.js. It shows great performance for both Node.js and browsers.
Vue.js
It is a library for building interactive web interfaces. It provides data-reactive components with a simple and flexible API.
See all alternatives