U.DOG
U.DOG

Reputation: 47

Adding static resources (css,js,htm) to grails 3 application

I am beginner in grails.
I would like to add some static resources to grails app and exclude them from url mappings.
I’ve added the following line to UrlMappings groovy:

class UrlMappings {
    static excludes = ['/resources/*']
...

But I don’t know how add resources to app and to the final war. Probably there is settings in build.gradle.
I want to open static html which can use static js/css/images.
Like this: localhost:8080/resources/index.html

Thanks in advance

Upvotes: 2

Views: 5062

Answers (2)

Duncan
Duncan

Reputation: 176

See the grails documentation on static resources. https://gsp.grails.org/latest/guide/resources.html

Note the following information on alternatives to the asset pipeline.

If you do not want to use the Asset-Pipeline plugin, you can serve the static assets from directories src/main/resources/public or src/main/webapp, but the latter one only gets included in WAR packaging but not in JAR packaging.

Upvotes: 2

Emmanuel Rosa
Emmanuel Rosa

Reputation: 9885

Since Grails 2.4, static assets are managed by the Asset Pipeline plugin. It's well documented, but it amounts to placing static content in either:

  1. grails-app/assets/javascripts
  2. grails-app/assets/stylesheets
  3. grails-app/assets/images

Then pull them into your GSP view with the <asset> tag:

<asset:javascript src="something.js"/>
<asset:stylesheet src="something.css"/>
<asset:image src="something.png" width="200" height="200"/>

It's quite easy, just read the documentation.

Upvotes: 6

Related Questions