Search code examples
templatesmemory-leakstransparencyunderscore.js-templatingplates

Best way to reuse a complex HTML fragment


I want to reuse the html of a complex UI that I created using underscore template. The issue is that the template constructor takes the data and generates the plain html with data. Now, I want to cache the generated html for future to use it as a template and would change the data of specific html nodes by selecting each of them using jQuery selectors.

My goal is to reduce the memory consumption by keep re-using the JS and DOM objects once created.

Has anybody done something like this before?


Solution

  • Okay. I myself have found a way. I am caching the DOM fragment (without removing from body) prepared by underscore template. When next time same fragment is needed, I re-use the cached fragment by updating the values using jQuery selectors.

    It is still WIP but looks promising.