wro4j icon indicating copy to clipboard operation
wro4j copied to clipboard

CSS URL rewriting fails when Bootstrap is in a WebJar

Open mwanji opened this issue 12 years ago • 35 comments

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

mwanji avatar Jun 19 '13 20:06 mwanji

This one requires a special attention :)... thanks for pointing it out.

alexo avatar Jun 19 '13 20:06 alexo

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

dtrunk90 avatar Jun 20 '13 20:06 dtrunk90

I am also having issues with bootstrap 2.3.2 LESS file.

everson avatar Aug 14 '13 13:08 everson

Any news on this?

dtrunk90 avatar Aug 27 '13 17:08 dtrunk90

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.

alexo avatar Aug 27 '13 17:08 alexo

Any updates?

s4gh avatar Jan 27 '14 16:01 s4gh

@sveryovka will be one of the priority issues for the next release. Until then, use classpath uri instead.

alexo avatar Jan 27 '14 16:01 alexo

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)

greg-pendlebury avatar Jun 02 '14 05:06 greg-pendlebury

The webjar itself shouldn't be avoided. What is the expected path of the image?

alexo avatar Jun 02 '14 05:06 alexo

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?

greg-pendlebury avatar Jun 02 '14 05:06 greg-pendlebury

Could you enable debug level log? It might be authorization related issue.

alexo avatar Jun 02 '14 05:06 alexo

Check if disableCache property is set to true. This has a side effect (a known issue). Set it to false.

alexo avatar Jun 02 '14 05:06 alexo

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?

greg-pendlebury avatar Jun 02 '14 05:06 greg-pendlebury

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.

alexo avatar Jun 02 '14 06:06 alexo

Cool. Thanks for your help.

greg-pendlebury avatar Jun 02 '14 06:06 greg-pendlebury

Hi. Is there any progress on this bug ?

arenard avatar Feb 20 '15 15:02 arenard

Hi @arenard,

there was no progress yet. Any contribution would speed things up..

Thanks, Alex

alexo avatar Feb 20 '15 16:02 alexo

Thank you for your update.

I'll try to look at it. Do you already have some hints on the bug location ?

arenard avatar Feb 20 '15 16:02 arenard

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

alexo avatar Feb 20 '15 16:02 alexo

Still no news?

Veske avatar Jun 26 '15 08:06 Veske

@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.

alexo avatar Jun 26 '15 09:06 alexo

Thank you, that does the trick for now.

Veske avatar Jun 26 '15 18:06 Veske

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 ?

sbrown44 avatar Sep 02 '15 11:09 sbrown44

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 avatar Sep 02 '15 12:09 sbrown44

@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).

alexo avatar Sep 02 '15 12:09 alexo

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: file:/home/sabrown/projects/schedules-classrooms/src/main/resources/static/scss/*.scss wro.properties: preProcessors=sassCss postProcessors=jsMin,cssMin

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;

sbrown44 avatar Sep 07 '15 18:09 sbrown44

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 avatar Sep 08 '15 13:09 sbrown44

@sbrown44 glad you have figure it out.

alexo avatar Sep 09 '15 11:09 alexo

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 avatar Oct 30 '15 12:10 hantsy

@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

alexo avatar Oct 30 '15 12:10 alexo