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

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

问题描述

最近升级了一个grails项目到2.3.7和插件到他们的最新,它带来了资源插件1.2.7。这工作正常Grails 2.1.2和资源插件1.2RC3,但现在不是:



每当我有一个css文件通过URL这样的

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

在网页上导致此错误'在网址正面)


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



解决方案

根据我之前的评论,这不是我的问题, / images / css / js Grails中的adhoc资源和我正在使用图像中的 .png 文件测试。



我从我的同事那里再次发现了这个问题,这让我想了两次。 :)在他的情况下,他试图访问由应用程序中使用的插件提供的 / fonts 中的字体。



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

  //不需要
//grails.resources.rewrite.css = false

我正在处理一个字体资源。



最后,将 Config.groovy 添加为 fonts 制作的伎俩。对于你的情况,你需要做如下:

  grails.resources.adhoc.includes = ['/ img / * *'] 
//如果从插件提供资源
//grails.resources.adhoc.includes = ['/ plugins / **','/ img / **']

如果您已经有这个配置,它看起来像:

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

但是正如我说的,你可能不需要添加adhoc




  • code> grails clean (更安全的一面)

  • grails run-app

  • 清除浏览器缓存(如果Chrome使用,我宁愿使用Chrome中的隐身模式)

  • 点击应用网址



它不应再抱怨资源了。


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

解决方案

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.

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

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