wro4j
wro4j copied to clipboard
CSS URL rewriting fails when Bootstrap is in a WebJar
When I put bootstrap.css in src/main/resources and use the classpath locator, it works:
<css>classpath:bootstrap/2.3.2/css/bootstrap.css</css>
But with the Bootstrap WebJar, I get the following error:
<css>webjar:bootstrap.css</css>
Exception occured while processing: ro.isdc.wro.WroRuntimeException: Could not replace imageUrl: ../img/glyphicons-halflings.png, contained at location: webjar:bootstrap.css, class: ro.isdc.wro.WroRuntimeException,caused by: (ro.isdc.wro4j:wro4j-maven-plugin:1.7.0:run:default:compile) pom.xml /radar-webapp line 62 Maven Build Problem
This one requires a special attention :)... thanks for pointing it out.
Same for Font Awesome:
2013-06-20 22:38:49 DEBUG ro.isdc.wro.http.WroFilter:347 - Exception occured
ro.isdc.wro.WroRuntimeException: Could not replace imageUrl: ../font/fontawesome-webfont.eot?v=3.2.1, contained at location: webjar:font-awesome.min.css
I am also having issues with bootstrap 2.3.2 LESS file.
Any news on this?
Not started to work on it, but it is next on my list before releasing next version.
Alex On 27 Aug 2013 20:21, "Danny Trunk" [email protected] wrote:
Any news on this?
— Reply to this email directly or view it on GitHub.
Any updates?
@sveryovka will be one of the priority issues for the next release. Until then, use classpath uri instead.
Does this mean that webjars with css/img combos should be avoided? or just the 'webjar:' syntax? I seem to be having the same URL rewrite problem when using:
<css>classpath:/META-INF/resources/webjars/bootstrap/2.3.2/css/bootstrap.min.css</css>
The CSS loads fine, but the rewritten images do not: http://localhost:8085/static/annotator.css (works) http://localhost:8085/static/annotator.css?wroAPI=wroResources&id=classpath:/META-INF/resources/webjars/bootstrap/2.3.2/img/glyphicons-halflings.png (does not: 404)
The webjar itself shouldn't be avoided. What is the expected path of the image?
I'm not certain... but the one it is using looks correct to me. I unpacked the 2.3.2 bootstrap webjar and the layout seems to lineup with what wro4j is generating. I'm just not certain why the CSS resolves but not the IMG. Do I need any extra configuration in web.xml or wro.properties to make 'wroAPI=wroResources' work?
Could you enable debug level log? It might be authorization related issue.
Check if disableCache property is set to true. This has a side effect (a known issue). Set it to false.
Good call: "ro.isdc.wro.http.support.UnauthorizedRequestException: Unauthorized resource request detected: classpath:/META-INF/resources/webjars/bootstrap/2.3.2/img/glyphicons-halflings.png"
And changing these made the problem go away:
disableCache=false
resourceWatcherUpdatePeriod=3
Sidenote... is there anyway to elevate things like that out of the debug channel?
It is a bug. Do not use the disableCache at all. You have other mechanisms available, like resourseWatcherUpdatePeriod. There is no point in elevating this kind of logs, since you will get your logs polluted in case of very likely anauthorized access. However you can enable debug for this particular class which checks for authorization.
Cool. Thanks for your help.
Hi. Is there any progress on this bug ?
Hi @arenard,
there was no progress yet. Any contribution would speed things up..
Thanks, Alex
Thank you for your update.
I'll try to look at it. Do you already have some hints on the bug location ?
The css url rewriting is the responsibility of the CssUrlRewritingProcessor class. But the actual fix should be implemented in ImageUrlRewriter class. There are plenty of unit tests which should help..
Thanks, Alex
Still no news?
@Veske The project location has moved to a new location The issue tracking this problem is located here Notice the last comment on that issue, which suggest a workaround, until the actual fix is implemented and released.
Thank you, that does the trick for now.
I looked at the issue in the code, and it seems as though a processor could be added to the extensions for webjars css url rewriting. Is this the approach you were going to take to fix this or were you going to try to completely refactor the rewriting code to actually use the registered location providers ?
One other thing, for anyone using the maven / eclipse plugins you can use the classpath: url for the css in the webjar and then the image rewriting works. ie replace webjar: with classpath:/META-INF/resources/webjars. Maybe obvious for some, but it took me more than a few minutes to figure that out.
@sbrown44 thanks for pointing this out. Indeed, "webjar" uri is not mandatory and it can be replaced with the "classpath" uri. The only disadvantage is that you have to hardcode the webjar version into the uri, as opposed to figuring it out automagically (as webjar locator does).
Having more problems with url rewriting in standalone maven build. Although using classpath uris allows the build to succeed the actual rewritten url is not useful, it seems to depend on wro4j servlet running in the application to be resolved. Also, when the resource is not a webjar or classpath resource, ie our own code, the rewriting is always to a file: url with an absolute path, which is not right for a maven build. And there seems to be no way to turn off url rewriting when using cssSass. This is a complete blocker for what we are trying to do, which is simply to run the sass processor and package up the css on our own code.
wro.xml:
source url entry: ( main.scss ) background: #fafafa url('../images/background/chairs56-162.jpg') no-repeat center center; result: ( main.css) background: #fafafa url('file:/home/sabrown/projects/schedules-classrooms/src/main/resources/static/images/background/chairs56-162.jpg') no-repeat center center;
Sorry I am being a bother, figured out why I could not get url rewriting turned off, there was a typo in the class name for the ConfigurableWroManagerFactory, so it was not actually using the property file. Running mvn -X gave lots of useful debug info. I have my sass working with rubySassCss. sassCss always seems to give empty content and does not work. Thanks
@sbrown44 glad you have figure it out.
I would like there is some function to copy the static resources(esp. fonts, images) to a specified folder when using webjars, and skip to replace the url value of the css.
@hantsy Could you elaborate? Also, the main project has migrated to a different location. We could continue discussing it here: https://github.com/wro4j/wro4j/issues/748