URLs within CSS files broken with Grails resources plugin 1.2.7

心不动则不痛 提交于 2019-11-27 14:41:04

According to my comment earlier, this wasn't an issue for me because by default all resources under /images, /css and /js are served as adhoc resources in Grails and I was testing with a .png file from images.

I came across this issue again from my colleague which made me think twice. :) In his case, he was trying to access fonts from /fonts which is provided by a plugin used in the app.

Before trying the below answer, I tried to disable css rewriting by adding the below configuration:

//Not required
//grails.resources.rewrite.css = false

but it made no sense for me as I was dealing with a font resource.

Ultimately, adding this as part of Config.groovy for fonts made the trick. For your case, you would need to do like below:

grails.resources.adhoc.includes = ['/img/**']
//If resource served from a plugin
//grails.resources.adhoc.includes = ['/plugins/**', '/img/**']

If you already have this configuration, it would look something like:

grails.resources.adhoc.includes = [
    '/images/**', '/css/**', '/js/**', '/img/**'
]

But as I said you might not need adding adhoc includes for existing resources in a grails app.

Go ahead with

  • grails clean (to be on the safer side)
  • grails run-app.
  • Clean browser cache (I would prefer an incognito mode in Chrome, if Chrome used)
  • Hit app url

It should not complain about the resource any more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!