Reputation: 101
I've been coding in grails now for a couple months. They get added to the page through the main.gsp file with the following:
<g:javascript library="jquery"/>
<r:require module="jquery-ui"/>
The jquery and jquery-ui plugins have been working fine for dialogs, sorting, etc, but I want to add the tabs widget to my pages now and the versions of jquery and jquery-ui that come with the plugins framework don't seem to work with them. When I add the sources directly to a page:
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>
everything works fine. So now I'm thinking of dumping the plugins entirely and just adding the libs in manually.
What is the best way to go about doing this? I could put them in the /js directory and modify ApplicationResources.groovy to reference them, but a co-worker mentioned he preferred adding them to the grails.resources.modules section of Config.groovy. I would like to know what the best way to accomplish this would be.
I also have the following in Config.groovy:
grails.resources.modules = {
overrides {
'jquery-theme' {
resource id: 'theme', url: '/css/smoothness/jquery-ui-1.10.0.custom.css'
}
}
Do I need to move this somewhere else or change it if I remove the plugins and manage the libs myself?
Upvotes: 6
Views: 3946
Reputation:
The two options are valid. You can work with the Config.groovy
or ApplicationResources.groovy
.
Before removing the plugins I suggest you to check if the version that you need exists. The plugin portal of grails.org will show you only the latest version. I tried here and :jquery:1.9.1
exists but :jquery-ui:1.10
not.
So, if you need, you can declare your resources for JQuery and JQuery UI. Just remove the plugins and the overrides, and add your configs. The files must go in js and/or css folders.
You can also check the environment and change to the minified version if needed. Example:
//use the minified version in production
def minified = GrailsUtil.isDevelopmentEnv() ? "" : ".min"
modules = {
jquery {
resource url: "/js/jquery-1.9.1${minified}.js"
}
'jquery-ui' {
resource url: "/js/ui/1.10.2/jquery-ui${minified}.js"
resource url: "/css/smoothness/jquery-ui-1.10.0.custom${minified}.css"
}
}
Upvotes: 8