There are several libs for JavaScript templates (Mustache, underscore templates). What they do is to create new DOM nodes.
In my app I am trying to reuse DOM nodes to decrease memory consumption. An example is a thumbnail gallery with pagination. I reuse the same 50 nodes when i load the 50 next thumbnails.
I could easily render new nodes with a template lib, but is there some template libs that instead of creating new nodes, can reuse or update existing ones?
My solution is somehow like adeneo’s but a little more generic. I use this in my projects, it uses only native DOM API, keep js and html totally separated.
Note that, white spaces should be removed when send to client.
First generate a template based on the delivered HTML, it takes a root element, and some binding points as parameters.
Then use data to generate
<li>s.When need to update one instance, you can do it like:
Now the list is generated.
The Tmpl class (minimized, removed other features, and works without any dependency) is pasted below: