Rendering and re-rendering a Mustache template I want to ask whether my following implementation is good in the view of good practice and performance. I have an app where I have to show another page or template html in an iframe. I get that template html via ajax and render it in the iframe. Iframe must be used because the template must be isolated.I am now storing that template html in a javscript variable

var tmp;
$.get('/template/1', function(data){  tmp = $(data); });
// tmp = '&lt;html&gt;&lt;body&gt;....etc...&lt;/body&gt;&lt;/html'; holds whole template


and then I have my div container in that template where I use mustache for changing content.

var render = tmp.find('#container').html();
var rendered = Mustache.to_html(render, some_data);
//then
tmp.find('#container').html(rendered);
// and add tmp to iframe


I am storing whole html in tmp so that it can be used later also and when my some_data change I again process tmp and re-render template in iframe. I may need re-render template many times later so I am storing in in variable. Is it good to store whole template html in javascript variable like that or it's better use other ways...if there are other ways what are they...
I don't think this will cause you any problems; it may offer superior performance in many scenarios, especially over re-rendering the template. The only other option that comes to mind is to keep this invisibly in the DOM somewhere and use JQuery's clone() to re-render it as needed. I use this latter technique especially if the original template is pre-rendered from another source. Just bear in mind that if you do use clone() JQuery also clones element IDs if you have any, which may cause your selectors on those IDs to behave unexpectedly if you don't change them after the clone (or refactor the source template).