Casey Flynn
Casey Flynn

Reputation: 14038

Combining templates to be used with backbone js

I'm getting started with backbone js, and I'm interested in combining all of my templates for various parts of my web application into one file and then caching it. I'm looking at _underscore and EJS for templating engines. Anyone have any experience with this?

Upvotes: 0

Views: 601

Answers (2)

Alexis Abril
Alexis Abril

Reputation: 6459

Similar to stusmith's suggestion, you can use StealJS to compile EJS templates(or any js file).

Within your app files you can setup dependencies, such as your templates and other resources:

steal('jquery', 'template_a.ejs', 'template_b.ejs', function() {

  //some app code

});

Then you can use the steal build tool to combine all your dependencies into one or many minified, concatenated files.

Upvotes: 0

stusmith
stusmith

Reputation: 14093

One option is to use RequireJS, which includes a 'text' plugin for templates.

You can then use the r.js optimizer to combine all of these (plus JS modules, if you go that route) into a single file.

The optimizer can be run either as part of your build process, or in-process if you're using node.js.

Upvotes: 2

Related Questions