17

Recently upgraded a grails project to 2.3.7 and plugins to their newest, which has brought Resources plugin to 1.2.7. This worked fine with Grails 2.1.2 and resources plugin 1.2RC3, but now it is not:

whenever I have a css file that references something via a URL like this

.checkbox-input-wrap.checked {
  background-image: url(/img/uniform-assets/checkbox.png);
}

On the webpage it leads to this error (it is leaving 'resource:/' on the front of the URL)

GET resource:/img/uniform-assets/checkbox.png net::ERR_UNKNOWN_URL_SCHEME

Charles
  • 50,943
  • 13
  • 104
  • 142
Peter
  • 29,498
  • 21
  • 89
  • 122
  • Unable to replicate the issue. Able to access any resource with resources 1.2.7. Can you add more info to debug? – dmahapatro Mar 25 '14 at 02:50
  • 1
    I have the same problem with grails 2.3.6 and resources plugin 1.2.7 and haven't been able to fix the issue. Works fine with plugin version 1.2.1 so I just reverted for time being. – ascu Mar 25 '14 at 09:44
  • @ascu downgrading has worked for me also. Going to poke around a bit more. – Peter Mar 26 '14 at 17:06
  • 1
    I have a very similar problem with 2.3.7 and the 1.2.7 version of the plugin. Fonts aren't loading -- GET resource:/fonts/open-sans/Bold/OpenSans-Bold.svg net::ERR_UNKNOWN_URL_SCHEME – David West Apr 03 '14 at 15:48

1 Answers1

26

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.

dmahapatro
  • 49,365
  • 7
  • 88
  • 117
  • I also noticed the issue with /fonts files. I thought I had tried with an update to my adhoc includes but will try again given your success. – Peter Apr 04 '14 at 22:20
  • I hope you will hit a success this time. You might have added as `adhoc.patterns` instead of `adhoc.includes` because I was confused for a moment as well. :) @Pete – dmahapatro Apr 04 '14 at 22:25
  • Works! Note we are also using cached-resources and zipped-resources and all appears good. It didn't work for me originally as my browser was caching something and I needed to shift+refresh after adding the proper adhoc includes (not usually necessary using cached-resources). – Peter Apr 04 '14 at 22:32