My Emberjs app is running slowly so I wanted to precompile my template to ease the runtime a bit. However I'm lost on how to proceed. I read http://handlebarsjs.com/precompilation.html and Emberjs introduction but no, all I could do was just creating a template file as instructed on the site, and I cannot figure out what and how to do with this template file in Emberjs.
How can I precompile templates in Emberjs? What should I do with the template file to use it in Emberjs?
Best Answer
To clarify, Thomas' example as-written is still doing the template compilation at run-time. I think his point, though, was that after you've loaded your precompiled Ember-Handlebars templates you can do this:
The problem with using Handlebars' built-in precompiler is that Ember's Handlebars implementation adds some functionality on top of what Handlebars itself provides, so you'll want to install the ember-precompile package, which provides basically the same interface as the
handlebars
command-line utility, but using Ember's Handlebars implementation.This will avoid you having to change all your
templateName
s totemplate
s and having to add in theEmber.TEMPLATES...
in each view, since it automatically updates Ember's built-in template cache.So, assuming you've already loaded your pre-complied
templates.js
file as output fromember-precompile templates/*.handlebars -f templates/templates.js
, here's a more complete example snippet of a worker import/initialization order: