When the CssLinkResourceTransformer use the ResourceResolverChain#resolveUrlPath method to retrieve a resource referenced with url or @import, it gives as parameter the complete path. This is not what the ResourceUrlProvider does: before calling the chain, it removes the beginning of the path corresponding to the matching pattern.
Imagine you have the following configuration: registry.addResourceHandler("/css/**").addResourceLocations("classpath:/statics/css/")
If I resolve '/css/app.css' with ResourceUrlProvider, PathResourceResolver receives 'app.css' to resolve.
Now imagine in app.css a statement like this: @import "/css/app2.css";
In that case PathResourceResolver receives '/css/app2.css' from CssLinkResourceTransformer instead of 'app2.css'. The chain will return null and URL won't be transformed.
CssLinkResourceTransformer should rely on the same mechanism as ResourceUrlProvider.
Great!
Note that using absolute paths in CSS files is now possible, but relative paths should be used in priority here. Client build tools prefer relative paths to concatenate and minify resources (in your case, this point is not relevant). But still, if you're deploying an application where servlet or context paths change, those absolute paths will change as well...
Thanks for all your feedback, we really appreciate it.
Guillaume DROUET opened SPR-12137 and commented
Hi,
When the CssLinkResourceTransformer use the ResourceResolverChain#resolveUrlPath method to retrieve a resource referenced with url or
@import
, it gives as parameter the complete path. This is not what the ResourceUrlProvider does: before calling the chain, it removes the beginning of the path corresponding to the matching pattern.Imagine you have the following configuration: registry.addResourceHandler("/css/**").addResourceLocations("classpath:/statics/css/")
If I resolve '/css/app.css' with ResourceUrlProvider, PathResourceResolver receives 'app.css' to resolve.
Now imagine in app.css a statement like this:
@import
"/css/app2.css";In that case PathResourceResolver receives '/css/app2.css' from CssLinkResourceTransformer instead of 'app2.css'. The chain will return null and URL won't be transformed.
CssLinkResourceTransformer should rely on the same mechanism as ResourceUrlProvider.
Affects: 4.1 RC2
Referenced from: commits 125ae99
The text was updated successfully, but these errors were encountered: