open class VersionResourceResolver : AbstractResourceResolver
Resolves request paths containing a version string that can be used as part of an HTTP caching strategy in which a resource is cached with a date in the distant future (e.g. 1 year) and cached until the version, and therefore the URL, is changed.
Different versioning strategies exist, and this resolver must be configured with one or more such strategies along with path mappings to indicate which strategy applies to which resources.
ContentVersionStrategy
is a good default choice except in cases where it cannot be used. Most notably the ContentVersionStrategy
cannot be combined with JavaScript module loaders. For such cases the FixedVersionStrategy
is a better choice.
Note that using this resolver to serve CSS files means that the CssLinkResourceTransformer should also be used in order to modify links within CSS files to also contain the appropriate versions generated by this resolver.
Author
Rossen Stoyanchev
Author
Brian Clozel
Since
5.0
See Also
VersionStrategy
VersionResourceResolver()
Resolves request paths containing a version string that can be used as part of an HTTP caching strategy in which a resource is cached with a date in the distant future (e.g. 1 year) and cached until the version, and therefore the URL, is changed. Different versioning strategies exist, and this resolver must be configured with one or more such strategies along with path mappings to indicate which strategy applies to which resources.
Note that using this resolver to serve CSS files means that the CssLinkResourceTransformer should also be used in order to modify links within CSS files to also contain the appropriate versions generated by this resolver. |
open fun addContentVersionStrategy(vararg pathPatterns: String): VersionResourceResolver
Insert a content-based version in resource URLs that match the given path patterns. The version is computed from the content of the file, e.g. |
|
open fun addFixedVersionStrategy(version: String, vararg pathPatterns: String): VersionResourceResolver
Insert a fixed, prefix-based version in resource URLs that match the given path patterns, for example: The version may be a random number, the current date, or a value fetched from a git commit sha, a property file, or environment variable and set with SpEL expressions in the configuration (e.g. see If not done already, variants of the given |
|
open fun addVersionStrategy(strategy: VersionStrategy, vararg pathPatterns: String): VersionResourceResolver
Register a custom VersionStrategy to apply to resource URLs that match the given path patterns. |
|
open fun getStrategyMap(): MutableMap<String, VersionStrategy>
Return the map with version strategies keyed by path pattern. |
|
open fun setStrategyMap(map: MutableMap<String, VersionStrategy>): Unit
Set a Map with URL paths as keys and Supports direct URL matches and Ant-style pattern matches. For syntax details, see the AntPathMatcher javadoc. |