Grails 2.3 changes css font-face url to "resource:/..."
Asked Answered
A

2

9

I want to include a custom font in my CSS like this:

@font-face
{
    font-family: TheFont;
    src: url(fonts/SourceSansProLight.ttf);
}

The CSS is served with Grails 2.3 and the CSS is modified to become this

@font-face
{
    font-family: TheFont;
    src: url(resource:/css/fonts/fonts/SourceSansProLight.ttf);
}

The resulting font url scheme is unknown and browsers can't open that file. Chrome, for example, reports:

GET resource:/css/fonts/fonts/SourceSansProLight.ttf net::ERR_UNKNOWN_URL_SCHEME 

/css/fonts is prepended to the original URL as well.

How can I instruct Grails to leave the font-face URL exactly as it is?

Adonic answered 28/2, 2014 at 7:56 Comment(2)
I usually use a path relative to the CSS file itself - e.g. ../images/foo.jpg.Neckcloth
Also you can try grails.org/plugin/asset-pipeline plugin, it will convert path under the hoodBiffin
A
14

The solution was to disable CSS processing in Config.groovy:

grails.resources.rewrite.css = false

I found the tip how to do that on the Grails mailing list.

Adonic answered 4/3, 2014 at 11:16 Comment(1)
I really dont undestand what this do, but i put it in my Config.groovy and starts throwing a strange errorWeslee
H
6

A better solution I think is proposed by dmahapatro at: https://mcmap.net/q/699962/-urls-within-css-files-broken-with-grails-resources-plugin-1-2-7

You need to ensure your font files are known to the Resources plugin.

The following worked for me in my Config.groovy, adapt it based on your paths:

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

You'll needed to run grails clean after making this change.

Hesson answered 8/8, 2014 at 14:53 Comment(2)
throw the same error with complete clean/compile/run-appWeslee
This ended up being the better answer than the one that was listed above. Wish yours was marked correct instead.Granulate

© 2022 - 2024 — McMap. All rights reserved.