Where should I put javascript libraries in a Grails app?

Simon picture Simon · Jan 11, 2010 · Viewed 17.6k times · Source

I have a couple of Javascript libraries of my own that do some nice prettyfying of my HTML pages and I want to include them in my gsp pages, particularly the landing page of my app. I have tried putting them in views folder and web-app/js and $APP_HOME/scripts but when I load my index.gsp the scripts don't show up.

I have also tried a variety of alternatives in my code none of which work...

<script src="mylib.js" type="text/javascript"></script>
<script src="js/mylib.js" type="text/javascript"></script>
<script src="scripts/mylib.js" type="text/javascript"></script>

I'm sure there is a clever grails way of doing this on the fly, but I really just want a location where I can place some boilerplate JavaScript code that I can use in my app. With convention over configuration in mind, what is the expected practice?

Answer

user249175 picture user249175 · Jan 12, 2010

You should probably NOT use <g:javascript library="myLib" /> as that is meant to be used as a way to make AJAX calls library (scriptaculous, dojo, yahoo, jquery) indifferent. See grails javascript. Instead use <g:javascript src="myLib.js" />.