Grails 2.3 changes css font-face url to “resource:/…”

江枫思渺然 提交于 2019-11-30 03:13:43

问题


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?


回答1:


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.




回答2:


A better solution I think is proposed by dmahapatro at: https://stackoverflow.com/a/22849288/2286664

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.



来源:https://stackoverflow.com/questions/22089379/grails-2-3-changes-css-font-face-url-to-resource

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