Using mustache.js,
I wish to rely on the browser standard page loader to load my mustaches.js templates.
In other words, I want to remove the JQuery request ($.get) to get the templates into memory, yet leaving the template into a separate html file. For now this work:
File contact.html:
<script id="tpl-test" type="text/html">
<h1> {{firstname}} </h1>
</script>
File my.js
$.get("tpl/contact.html", function(templates){
var template = $(templates).filter('#tpl-test').html();
var jdata={firstname: 'fname'};
$('body').append(Mustache.render(template, jdata));
});
And I wish to have something similar to this:
File contact.html (remain as is)
and instead of a jquery $.get request, I would prefer:
In index.html:
<script id="tpl-test" src="tmpl/contact.html" type="text/html"></script>
Update: In Chrome, the template is loaded like this:
File my.js (my wish, but this does not work)
function ondemand(){
var template = $(templates).filter('#tpl-test').html();
var jdata={firstname: 'fname'};
$('body').append(Mustache.render(template, jdata));
});
Thanks in advance.