not familiar with ruby ββon rails syntax, but here is my trick:
a) Why do you even want to generate markup on the server side (if this is an option at all), always send json data to the client to the client and allow it to work with it.
b) if you still want to save the server-side rendering engine, then what you can do is save all your mustache templates in a folder, write the script that you execute during the build (or the equivalent in ruby ββon rails) that combines all templates in a well-chosen JS file with the correct naming conventions.
Something like the following:
var MUSTACHE_TEMPLATES= MUSTACHE_TEMPLATES || (function(){ var template1= "<big ass template>"; var template2="<small template>"; return { template1: template1, template2: template2 } }());
What do you think about it? Now you have your templates living in one place and you also get the benefits of caching a js file
source share