title: Client-side templating language with java compiler as well (DRY templating)
body: <p>I want to be able to define templates once and use them to render html from both the server-side as well as the client-side. (DRY principle and all that)</p>
  
  <p>The API that I'm envisioning is simply this: render(JSON, template) --> html. </p>
  
  <p>I'm using a java-framework (actually Play framwork, but I don't think this is framework specific). </p>
  
  <p>I've read a lot of similar questions, the latest, and most helpful being: <a href="https://stackoverflow.com/questions/5494839/templating-language-for-both-client-side-and-server-side-rendering">Templating language for both client-side and server-side rendering</a>. </p>
  
  <p>I pretty much agree with the author that obvious contenders like:  Mustache and Google Closure Templates are not going to cut it. (for reasons see that post)</p>
  
  <p>Requirements: </p>
  
  <ul>
  <li>MUST: client-side rendering </li>
  <li>MUST: client-side caching of template-files</li>
  <li>NICE: client-side 'compile-once execute many times' of template-file to fast javascript-code</li>
  <li>MUST: server-side rendering</li>
  <li>NICE: native java implementation</li>
  </ul>
  
  <p>I've seen a bunch of posts suggesting the use of Node.js for server-side templating. Although this would definitely work (underscore templates, Handlebarsjs, EJS would all work just fine) I'm struggeling to see how to communicate/combine/integrate Node.js with java, after all it's still the java framework that needs to output the JSON </p>
  
  <p>I've seen posts mentioning some proof-of-concept communicating between a JVM and node.js (over http or using JNDI) . However, no library, let alone battle-tested,  seems to be available at the moment. </p>
  
  <p>So to round things up, what client-side templating engine would you suggest that would run in java as well (or with some hoops, can be called from a jvm) ? And if that 'hoop' happens to be Node.js, what ways of communication/ library would you suggest to use?</p>