Harvard Extension School, Fall 2018
CSCI E-12 Fundamentals of Web Site Development

## Handlebars - Compiled Templates

It is possible to precompile your Handlebars template (the result is a JavaScript function), and then include the compiled templates via a `script` element.

Advantages of precompiling the templates include:

- Faster execution
- Can use lighter-weight Handlebars JS library (the "runtime" version, which doesn't have the compiler)

So here's an example where I've compiled the course list template into `courseslist.js`. Now there's no compile step, just a reference to `Handlebars.templates.courseslist` to access the template function. Note too that we are using the "runtime" version of the Handlebars library - `handlebars.runtime.min.js`

- Live Example - Handlebars Precompiled Template
- Handlebars Precompiled Template - JS Fiddle

Note the command to compile the template looked like:

    $ handlebars.js courseslist -f courseslist.js

where `courseslist` is the source template, and `courseslist.js` is the generated compiled JS file

Copyright © David Heitmeyer