CSS 文件中的 URL 被 Grails 资源插件 1.2.7 破坏 [英] URLs within CSS files broken with Grails resources plugin 1.2.7

查看:23
本文介绍了CSS 文件中的 URL 被 Grails 资源插件 1.2.7 破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近将 grails 项目升级到 2.3.7,并将插件升级到最新,这将 Resources 插件带到了 1.2.7.这适用于 Grails 2.1.2 和资源插件 1.2RC3,但现在不是:

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:

每当我有一个通过这样的 URL 引用某些内容的 css 文件时

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);
}

在网页上它会导致此错误(它在 URL 前面留下了资源:/")

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

获取资源:/img/uniform-assets/checkbox.png net::ERR_UNKNOWN_URL_SCHEME

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

推荐答案

根据我之前的评论,这对我来说不是问题,因为默认情况下 /images 下的所有资源/css/js 在 Grails 中用作临时资源,我正在使用 images 中的 .png 文件进行测试.

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.

我从同事那里再次遇到这个问题,这让我三思而后行.:) 在他的案例中,他试图从 /fonts 访问字体,该字体由应用程序中使用的插件提供.

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.

在尝试以下答案之前,我尝试通过添加以下配置来禁用 css 重写:

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

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

但这对我来说毫无意义,因为我正在处理 font 资源.

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

最终,将它添加为 fontsConfig.groovy 的一部分就成功了.对于您的情况,您需要执行以下操作:

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/**'
]

但正如我所说,您可能不需要为 grails 应用程序中的现有资源添加临时包含.

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

继续

  • grails clean(为了更安全)
  • grails run-app.
  • 清理浏览器缓存(如果使用 Chrome,我更喜欢 Chrome 中的隐身模式)
  • 点击应用网址

它不应该再抱怨资源了.

It should not complain about the resource any more.

这篇关于CSS 文件中的 URL 被 Grails 资源插件 1.2.7 破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆