jwhitley/requirejs-rails — Issue #16: Unable to serve text! template assets except via the /public folder
Author: malandrew
Created: 2011-12-16 19:20:03+00:00
State: open

Javascript templates saved in a folder such as ```/app/assets/templates/``` cannot be served because there is no route for that server.

How to best serve templates seems like a feature request that require(designDecision). From an efficiency point of view, I would say that a template should always be served with the javascript that is going to use it. Firing off an extra ajax request to get a template file looks like the simple solution, but is less than idea.

I'm a big fan of the approach Jammit took with javascript. it would minify the templates and serve them as one template per line of javascript like so:

```
(function () {
window.JST = window.JST || {};
window.JST["account/dialog"] = _.template('

');
window.JST["common/menu"] = _.template('<% var mid = id ? id + "_content" : \'\'; %>

');
window.JST["common/menubutton"] = _.template('

<%= label %>

');
window.JST["common/tooltip"] = _.template('

');
})();
```

If I remember correctly, if a different template engine other than JResig's micro templates, which is included with underscore, it would inline the template parser in the module.

Packaging the templates in layered approach could be interesting. For example, all the templates for the admin area could be one template package that returns an object with one template per Object property.