Phil opened SPR-15777 and commented
I'm currently using a Resource Handler for my CSS Files and additionally a CSS Link Resource Transformer.
Actually the output looks like this
@font-face {
font-family:'bla';
src:url('fonts/bla-normal-075247c3b3e06129c47ca740a32dc7f4.eot');
src:url('fonts/bla-normal.eot?#iefix') format('embedded-opentype'),url('fonts/bla-normal-632750944fac21720bc3fb589824f72d.woff') format('woff'),url('fonts/bla-normal-f989315cb2ee10c6cf21368cd6ca9d0d.ttf') format('truetype'),url('fonts/bla-normal.svg#bla-normal') format('svg');
As you can see if a parameter like #bla-normal oder #iefix is present, the file would not be versioned anymore
Current Resource Handler (using multiple Resource Handlers)
registry.addResourceHandler("/static/css/**")
.addResourceLocations("/css/")
.setCachePeriod(cachePeriod)
.resourceChain(true)
.addTransformer(new CssLinkResourceTransformer())
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
CSS Files were generated on build from less Files
Affects: 4.3.7
Referenced from: commits https://github.com/spring-projects/spring-framework/commit/70252a7335f3136d661d1d8387e4452621c9ed37
Comment From: spring-projects-issues
Rossen Stoyanchev commented
Note that query or fragment are properly handled and the issue is specifically for relative links.
Comment From: spring-projects-issues
Rossen Stoyanchev commented
Actually I take that back. It seems to work because we turn relative links into absolute. See the modified tests that demonstrate it.
At this point I'm not sure what's going on. Would you mind debugging around this line to see what's going on? Or alternatively provide a sample project.
Comment From: spring-projects-issues
Phil commented
The current Resource Hanlder für css Files looks like this. Fonts are placed in a subdir of css (css/fonts). Actually for me there is no need of versioning fonts (except of changing icon fonts) but absolute URLs - that are not generated - would be an intersting feature in my app.
I'm trying to gather more information by time.
registry.addResourceHandler("/static/css/**")
.addResourceLocations("/css/")
.setCachePeriod(cachePeriod)
.resourceChain(true)
.addTransformer(new CssLinkResourceTransformer())
.addResolver(new VersionResourceResolver().addContentVersionStrategy("/**"));
Comment From: spring-projects-issues
Rossen Stoyanchev commented
It should be quite easy for you to exclude resources by overriding the protected method VersionResourceResolver#getStrategyForPath.
Comment From: spring-projects-issues
Rossen Stoyanchev commented
As for the issue, i'm still unsure how to reproduce. Ideally please provide a simple repro project.
Comment From: spring-projects-issues
Phil commented
Sorry for delayed response.
I have traced down the problem a little further. In my CSS file I use relative links, for instance ```java src:url('fonts/metawebpro-normal.eot')
This is correctly process in the ```java
CssLinkResourceTransformer
``` and
```java
resolveUrlPath(link, request, resource, transformerChain);
``` is called,
which in turn uses the transformerChain that contains our
PathResourceResolver. This PathResourceResolver calls its
resolveUrlPathInternal method that gets the Resource via the getResource
method. The arguments for the followgin two example for
getResource(String resourcePath, Resource location) are as follows:
```java
src:url('fonts/metawebpro-normal.eot')
-> resourcePath: fonts/metawebpro-normal.eot
-> location: /css/file.css + versio hash
but for
src:url('fonts/metawebpro-normal.eot?#iefix')
-> resourcePath: fonts/metawebpro-normal.eot?#iefix
-> location: /css/file.css + versio hash
In the second case with the trailing question mark / or hash the
getResource
``` method fails in the line containing ```java if (resource.exists()
&& resource.isReadable()) ```
and returns null. I think this causes the
problem that this resource is not transformed to one containing a
version hash properly.
I hope these information are sufficient.
Comment From: spring-projects-issues
Rossen Stoyanchev commented
resourcePath: fonts/metawebpro-normal.eot?#iefix
This doesn't look right and it's not obvious why?
CssLinkResourceTransformer uses ResourceUrlProvider to resolve the URL path which in turn strips the query/fragment before resolving the resource.
So the resourcePath shouldn't have a query in the first place. This is the place where CssLinkTransformer turns relative paths to absolute.
Could you investigate a little further based on this info?
Comment From: spring-projects-issues
Phil commented
Obviously the (old) Version we use (see Issue) does not contain absolute Urls
So actually don't care about that.
In CachingResourceResolver called by the CssLinkResourceTransformer transform Method as you mentioned the resolvedUrlPath returns null.
Afterwards it is getting a bit weird for me, at the moment I can't figure out where its systematically caused.
(The project does not give us much time so investigate, so i'm sorry for responding slowly)
Comment From: spring-projects-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-projects-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.