title: Grails: render file from assets folder into gsp
body: <p>I use require.js in a Grails project. There are a couple of single JavaScript files containing the require.js modules defined with <code>define</code>. </p>
  
  <p>There is also a *.gsp file which generates the require.js config and the entry point starting with <code>require()</code> as there is some dynamic configs to be generated. It looks somehow like this:</p>
  
  <pre><code>&lt;%@ page contentType="application/javascript;charset=UTF-8" %&gt;
  
  require(['a', 'b'], function(a, b){
      ...
      var a = ${controllerPropertyA};
      ...
      some functions        
      ...
  });
  </code></pre>
  
  <p>In my layout I integrate require.js like this:</p>
  
  <pre><code>&lt;script data-main='http://example.com/exampleController/dynamicGenerateMethod?domain=xyz.com' src='http://example.com/assets/require.js'&gt;&lt;/script&gt;
  </code></pre>
  
  <p>All the modules a , b, and so on are asynchronously loaded by require.js. Now I would like to bundle them into a single file - I could use the require.js optimize tool but I prefer to use the assets-pipeline. This works as far as that I get all modules bundled into a single <code>optimized-modules.js</code> which is available on <code>http://example.com/assets/optimized-modules.js</code>.</p>
  
  <p>The question: I would like to have the optimized JavaScript code in the dynamically rendered GSP file. So how can I inject the optimized-modules.js file into the GSP I'm dynamically rendering? I already thought about a tag defined in the tag library so that my *.gsp would look like</p>
  
  <pre><code>&lt;%@ page contentType="application/javascript;charset=UTF-8" %&gt;
  
  &lt;g:renderFile file="/assets/optimized-modules.js" /&gt;
  require(['a', 'b'], function(a, b){
      ...
      var a = ${controllerPropertyA};
      ...
      some functions        
      ...
  });
  </code></pre>
  
  <p>and the tag definition somehow like that:</p>
  
  <pre><code>    def g:renderFile = { attrs, body -&gt;
          def filePath = attrs.file
  
          if (!filePath) {
              throwTagError("'file' attribute must be provided")
          }
          //out &lt;&lt; filePath
          out &lt;&lt; request.servletContext.getResource(filePath).file
          //out &lt;&lt; grailsResourceLocator.findResourceForURI(filePath).file.text
          //out &lt;&lt; grailsApplication.mainContext.getResource(filePath).file.text
          //out &lt;&lt; Holders.getServletContext().getResource(filePath).getContent()
          //IOUtils.copy(request.servletContext.getResourceAsStream(filePath), out);
      }
  </code></pre>
  
  <p>But I can't get the content of the minified optimized-modules.js which was done by the assets-pipeline plugin on startup. Any thoughts on this?</p>