scotthovestadt / requirejs-underscore-tpl

RequireJS plugin to load and precompile underscore templates.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

underscore-tpl

underscore-tpl is a RequireJS plugin to load and precompile Underscore.js templates.

Here are some performance tests that show the difference when rendering precompiled templates.

Usage

Use the tpl! prefix when loading a template.

myview.js

define(['tpl!mytemplate.tpl'], function (template) {

  var MyView = Backbone.View.extend({
    template: template // just pass in the template
  });                  // do not use _.template(), at this point it is already compiled

  return MyView;
});

The plugin will compile the template after requirejs r.js optimizer.

And also when developing, it will compile the template the first time is loaded so that the next time is required it will just render the template saving a function call to underscore's internal render method.

Dependecies

For this plugin to work you need:

License

See LICENSE

About

RequireJS plugin to load and precompile underscore templates.

License:MIT License


Languages

Language:JavaScript 100.0%