简体   繁体   中英

Grails 3.0 How to use Javascript in GSP's?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM