I'm writing some new code and I'm considering using the Template functions of prototype. I've never used Template before. Is this function fast or would it be faster to return HTML from the server? In particular for a table with 250 items. Thanks for the advice!
on 2008-06-24 16:22
on 2008-06-24 16:31
How will you be building the table? I assume you're weighing the difference between returning HTML from the server, and returning something like JSON from the server and building the table in JS? I'd say building a 250 row table in JS with a Template will be plenty fast (will be noticeably faster than a DOM builder), and you can probably take advantage of some code reuse if you want to add/remove/reorder table rows dynamically. If the table is going to remain relatively static, probably no need to bother doing it on the client side. -Fred On Tue, Jun 24, 2008 at 9:21 AM, Namotco <namotco@gmail.com> wrote: > > I'm writing some new code and I'm considering using the Template > functions of prototype. I've never used Template before. Is this > function fast or would it be faster to return HTML from the server? > In particular for a table with 250 items. -- Science answers questions; philosophy questions answers.
on 2008-06-24 21:09
I am planning to add/remove/change rows dynamically with a JSON object. I will need to create a new template if I want to change how many rows there will be though, correct?
on 2008-06-24 21:16
Use one template for the rows inside a loop, and then wrap it in a <table>. -Fred On Tue, Jun 24, 2008 at 2:08 PM, Namotco <namotco@gmail.com> wrote: > > I am planning to add/remove/change rows dynamically with a JSON > object. I will need to create a new template if I want to change how > many rows there will be though, correct? -- Science answers questions; philosophy questions answers.
on 2008-06-24 23:05
Namotco wrote: > I'm writing some new code and I'm considering using the Template > functions of prototype. I've never used Template before. Is this > function fast or would it be faster to return HTML from the server? > In particular for a table with 250 items. > > Thanks for the advice! A few years ago I created a compile template class that compiles a template so that it can be evaluated very quickly. It is great for these situations where you are creating html from json. Check out the source with a table example at the end. http://pastie.org/221410 You may also notice that it supports complex Smarty-like constructs such as {if} and {foreach} and allows you to write more handlers for custom tags. - Ken Snyder
on 2008-06-25 01:24
Ken, pre-instantiating prototype's Template is actually relatively fast (vs. just using #interpolate on a string) Have you, by any chance, done any benchmarking? - kangax
on 2008-06-25 16:34
kangax wrote: > Ken, > pre-instantiating prototype's Template is actually relatively fast > (vs. just using #interpolate on a string) > Have you, by any chance, done any benchmarking? > > - kangax > I've done no benchmarking since the main functionality I wanted was if and foreach. But I'd be surprised if the eval() approach wasn't significantly faster than the gsub() approach. I've got a new version in the works so I'll have to do some benchmarking. - Ken