Mustache, using external templates
There are several approaches to doing this.
- If you are using a server side scripting language like PHP, just include them in a seperate
.mst
(the extension could be anything you want actually) file within the JS. For example,var _templateName = <?= JS::mustache('content/templateName.mst') ?>;
. Thus, when the JS is actually rendered, it will be rendered with the markup but the code will still be maintainable. Besides, with this approach, if you're using an CDNs, your site will benefit greatly with the cached JS. - The other approach is to load external HTML files with any of jQuery's
$.get
,$.getJSON
, etc. methods. A more detailed implementation of this is given here.