premasagar / tim

A tiny, secure JavaScript micro-templating script.
251 stars 26 forks source link

Make precompilation of templates possible. #16

Open zorbash opened 11 years ago

zorbash commented 11 years ago

Other javaScript templating engines support compiling the template text to a function which can then be called many times with different values without having the original template text be compiled again and again.

E.g in underscore templates:

    var compiled = _.template("hello: <%= name %>");
    compiled({name : 'moe'});
    "hello: moe"

Is there any "hidden" way you can do that with tim?

premasagar commented 11 years ago

@zorbash, unfortunately, there isn't currently a way to do this with tim. Everything is computed on-the-fly.

It's a good idea to have pre-computed templates, for performance, although I think it's likely that in most applications, the performance difference will be negligible. But no doubt there are situations where it will matter. I don't currently have any plans to implement it, but I'd happily review a pull request from someone.