Skip to content

Improvement suggestions to the ResourceTransformerChain [SPR-13806] #18379

@spring-projects-issues

Description

@spring-projects-issues

Felix Kurth opened SPR-13806 and commented

This is a follow up from #18300.

The customization possibilities for the resource chain should be improved.
Right now, if one adds a <resource-chain> tag to the xml, a complete default Resource chain is wired up according to ResourceChainRegistration.java.

<mvc:resources mapping="/resources/**" location="/"   >
        <mvc:resource-chain  >
            <mvc:resolvers >
                <mvc:version-resolver >
                    <mvc:fixed-version-strategy patterns="/**" version="1234" />
                </mvc:version-resolver>
            </mvc:resolvers>
        </mvc:resource-chain>
    </mvc:resources>

including a CssLinkResourceTransformer, AppCacheManifestTransformer, CachingResourceTransformer, CachingResourceResolver, WebJarsResourceResolver, PathResourceResolver,
depending whether the user has supplied a VersionResourceResolver or not.
\
\

  • Please give the developer a chance to disable the default transformers and resolvers without wiring up the complete chain itself.
    i tried to disable auto registration
<mvc:resource-chain resource-cache="false" auto-registration="false" >

But i was not able to wire up the chain myself. There seems to be no docs on that. Please add the possibility to configure the transformers:
I would expect that an empty element:

<mvc:transformers >
</mvc:transformers>

means no transformers, and no "default" implicit ones. Another option would be a property like

<mvc:transformers default-transformers="false" />

For all spring supplied transformers, there should then be an xml tag (or a property) available

<mvc:transformers default-transformers="false" >
	<mvc:css-link-resourcetransformer />
<mvc:transformers>

The same applies to the resolvers, have the possibility to disable the default ones.

  • For the version strategies, please add a NoVersionStrategy with its xml counterpart:
<mvc:no-version-strategy patterns="/images/*.png" />
  • Right now its not possible to use the FixedVersionStrategy with an empty or null version. I don't see a reason for that and would be convenient for a development profile etc. This would solve the NoVersionStrategy case as well.

  • The CssLinkResourceTransformer is not able to handle relative paths with a fixed version strategy, if the path is relative and does not start with an ".".
    For example from
    An example from jquery-ui.css

url("images/ui-bg_flat_100_ffffff_40x100.png")

will not work. If both, the css file and the url within it are are under a fixed version strategy, it may end up with a double version-ed path like

/resources/VERSION/styles/VERSION/images/abc.png

My suggestion to this problem: Do no chain up PrefixVersionPathStrategy's. So if

  • the css file the CssLinkResourceTransformer is currently parsing itself is version-ed with PrefixVersionPathStrategy,
  • AND
  • the url within the css currently under processing would lead to another PrefixVersionPathStrategy (for the png for example) then do not touch the url itself.

Affects: 4.2.4

Issue Links:

Referenced from: commits spring-attic/spring-framework-issues@139ad04

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions