Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
_CanHaz: Underscore template inspired on ICanHaz (github.com/bltavares)
4 points by bltavares on July 26, 2011 | hide | past | favorite | 4 comments


I like it. But it looks like it re-compiles the template every time. Or am I reading it wrong?


Didn't notice that. Thanks! I'm going to improve it (:


I see that you updated it so that it caches the final html for each unique set of parameters. I guess I should have better explained what I meant by "compiled".

If you pass the template text to the underscore function without any parameters, then it returns a function. Then you can call that function with different parameters and get different html back. That eliminates some of the work that underscore has to do repeatedly if you are rendering lots of templates. So I was thinking that when you loop through all the script headers and create methods for them, that you could also create the "compiled" underscore template function. Then, the template method that you create would take the parameters and pass them along to that "compiled" function to get the html back.

My apps wouldn't really have use for caching the final html, but maybe someone has a good use for that. If you leave it in, it should probably be an option, because it could use up a lot of memory depending on the app.


Thanks zargon (: I'm going to make it optional.

I've realized that I can store the Underscore template on the other day. Now it's fixed




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: