I am trying to understand how Ember takes on templates. Say, the templates are served as script tags inside the main html. When I render a Route, will Ember cache the DOM, compile the template and cache it, or neither? Is the precompile performance gain really just a one time thing during the first time a template is used?
A few reasons to pre-compile templates (addressing your point with number 2):
- Organization. It’s much cleaner to have your templates in separate files rather than all crammed into one file.
- As you mentioned, the runtime cost of compiling the template. Yes, Ember only does it once, but it’s still a cost that the client has to pay. Why make your user wait for an extra 2 to 3 seconds when you don’t have to?
- The Handlebars library size. The library with compiler is 90kb. Just the runtime is only 16kb.
- Caching. With the templates in Javascript rather than HTML files, they’re more likely to be cached by the browser.