79422480

Date: 2025-02-08 01:24:11
Score: 0.5
Natty:
Report link

I tried a lot of approaches besides the ones mentioned above but nothing seem to work. Also considering I did not want the reactjs components to intrude with the grails javascript I did below workaround - hope this might help someone else stuck with similar situation.

I moved the compiled bundle.js into src/main/resources/ and created this ContentController to serve the file as raw javascript file:

@Controller
class ContentController extends RestfulController{
    def bundle(){
        def myBundleFileContents = getClass().getResource('/bundle.js').text
        response.setHeader("Content-disposition", "filename=bundle.js")
        response.contentType = 'text/javascript'
        response.outputStream << myBundleFileContents
        response.outputStream.flush()
    }
//more actions
}

Then I included the bundle file in my gsp page as below:

<script type="text/javascript" src="../content/bundle">
</script>
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Amit Thakur