To follow best practices use the Grails Asset Pipeline. It may take a bit of practice to understand how the pipeline works but the general ideas are highlighted well in this SO Answer. The pipeline will create folders for your assets, (css, javascript, images for example) and you need to place your bootstrap files in the proper locations. Make sure you remember that Bootstrap requires jQuery.
Please note that all JavaScript plugins require jQuery…
So be sure to include jQuery in your javascript folder. The other concept to grasp is creating the manifest file. For javascript assets it might look similar to:
Example file path:
grails-app/assets/javascripts/application.js
Example file contents:
//This is a JavaScript file with its top level require directives
//= require jquery
//= require app/models.js
//= require_tree views
//= require_self
console.log("This is my javascript manifest");
Then in the view you would like to uses the assets in, include the bootstrap assets by declaring:
<head>
<asset:stylesheet href="application.css"/> //This assumes the standard pipeline path
<asset:javascript src="application.js"/>
<asset:link rel="shortcut icon" href="favicon.ico" type="image/x-icon"/>
</head>
Hopefully that helps you get started with loading Bootstrap via the asset pipeline.
2
Answers
To follow best practices use the Grails Asset Pipeline. It may take a bit of practice to understand how the pipeline works but the general ideas are highlighted well in this SO Answer. The pipeline will create folders for your assets, (css, javascript, images for example) and you need to place your bootstrap files in the proper locations. Make sure you remember that Bootstrap requires jQuery.
So be sure to include jQuery in your javascript folder. The other concept to grasp is creating the manifest file. For javascript assets it might look similar to:
Example file path:
Example file contents:
Then in the view you would like to uses the assets in, include the bootstrap assets by declaring:
Hopefully that helps you get started with loading Bootstrap via the asset pipeline.
You can use webjars
build.grade
grails-appstylesheetsapplication.css
grails-appjavascriptsapplication.js