alnafie alnafie - 1 year ago 127
Javascript Question

Difference between compile(), parse(), and render() in mustache.js

What is the difference between:

, and

in the new mustache.js version 0.5.0, and perhaps for bonus points you could tell us what the difference between parsing and compiling is in general.

Answer Source


With an API change introduced in version 0.8.0, the compile() method has been integrated into parse(). Manually compiling the templates is no longer required.


Syntactically parses the template and creates a JavaScript function body (a string) from it. During that process it notifies of any syntax errors encountered in the template.


Uses the function body returned from a successful parse() to create an actual JavaScript function. The created function is placed in a cache for re-use.


Takes the appropriate function for a given template (the one that was created by compile()) and applies it to actual data. This creates the result meant to be shown on screen.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download