1

The documentation says, that <r:script> is the right way to do this, but this is part of the Resources Plugin, which is not available in Grails 3.0, so I think in a single GSP the right way to use Javascript is at the end of the <body> with the <g:javascript>-tag.

Is there a better way to do this?

1 Answer 1

2

You can use <asset:javascript src="example.js" /> at the bottom of a GSP file.

However, SiteMesh inserts the body where <g:layoutBody /> is in the layout GSP, so there could end up being some other tags between <script> and the end of the <body>. It would be cleaner to create a separate layout GSP.

Also, be sure to not include example.js in application.js or else the special js file will end up on every page by default. One option is to create an assets/javascripts/public folder for everything else.

grails-app/assets/javascripts/application.js

//= require_tree ./public
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.