Editing Handlebars.js vs Mustache.js This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <style type="text/css"> #output { overflow: hidden; } #output .sample { width: 45%; padding: 1%; border: 1px solid #ccc; float: left; } </style> <script src="//cdnjs.cloudflare.com/ajax/libs/mustache.js/0.3.0/mustache.min.js"></script> <script src="//cdnjs.cloudflare.com/ajax/libs/handlebars.js/1.0.0.beta2/handlebars.min.js"></script> <script id="template_one" type="text/template"> <h3>{{header}}</h3> <ul> {{#items}} {{#first}}<li><strong>{{name}}</strong></li>{{/first}} {{^first}}<li>{{#link}}<a href="{{url}}">{{/link}}{{name}}{{#link}}</a>{{/link}}</li>{{/first}} {{/items}} </ul> {{#double}} <p>Double rainbow!</p> {{/double}} </script> <div id="output"> <div class="sample"> <h2>Mustache Renders</h2> <div id="mu"></div> </div> <div class="sample"> <h2>Handlebars Renders</h2> <div id="hb"></div> </div> </div> <script> var template = document.getElementById('template_one').innerText, data = { "header": "Colors", "items": [ { "name": "rainbow", "first": true, "url": "#Rainbow" }, { "name": "red", "link": true, "url": "#Red" }, { "name": "orange", "link": true, "url": "#Orange" }, { "name": "yellow", "link": true, "url": "#Yellow" }, { "name": "green", "link": true, "url": "#Green" }, { "name": "blue", "link": true, "url": "#Blue" }, { "name": "purple", "link": true, "url": "#Purple" }, { "name": "white", "link": false, "url": "#While" }, { "name": "black", "link": false, "url": "#Black" } ], "double": true }, hb_compiled; ui.benchmarks[1].setup = function() { hb_compiled = null; }; ui.benchmarks[2].setup = function() { hb_compiled = Handlebars.compile(template); }; document.getElementById('mu').innerHTML = Mustache.to_html(template, data); document.getElementById('hb').innerHTML = Handlebars.compile(template)(data); </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code Mustache.to_html('<h3>{{header}}</h3><ul>{{#items}}{{#first}}<li><strong>{{name}}</strong></li>{{/first}}{{^first}}<li>{{#link}}<a href="{{url}}">{{/link}}{{name}}{{#link}}</a>{{/link}}</li>{{/first}} {{/items}}</ul> {{#double}}<p>Double rainbow!</p>{{/double}}', data); Test 2 Title Async (check if this is an asynchronous test) Code Handlebars.compile(template)(data); Test 3 Title Async (check if this is an asynchronous test) Code if (!hb_compiled) { hb_compiled = Handlebars.compile(template); } hb_compiled(data); Test 4 Title Async (check if this is an asynchronous test) Code hb_compiled(data);