public class FixedVersionStrategy extends AbstractVersionStrategy
VersionStrategy
that handles unique, static, application-wide version strings
as prefixes in the request path.
Enables inserting a unique and static version String (e.g. reduced SHA, version name, release date) at the beginning of resource paths so that when a new version of the application is released, clients are forced to reload application resources.
This is useful when changing resource names is not an option (e.g. when
using JavaScript module loaders). If that's not the case, the use of
ContentBasedVersionStrategy
provides more optimal performance since
version is generated on a per-resource basis: only actually modified resources are reloaded
by the client.
VersionResourceResolver
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
version |
logger
Constructor and Description |
---|
FixedVersionStrategy(java.util.concurrent.Callable<java.lang.String> versionInitializer)
Create a new FixedVersionStrategy and get the version string to use by
calling the given
Callable instance. |
FixedVersionStrategy(java.lang.String fixedVersion)
Create a new FixedVersionStrategy with the given version string.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
addVersionToUrl(java.lang.String baseUrl,
java.util.List<? extends Resource> locations,
ResourceResolverChain chain)
Adds a version string to the given baseUrl.
|
java.lang.String |
deleteVersionFromPath(java.lang.String requestPath,
java.lang.String candidateVersion)
Deletes the given candidate version string from the given request path.
|
java.lang.String |
extractVersionFromPath(java.lang.String requestPath)
Extracts a version string from the request path.
|
boolean |
resourceVersionMatches(Resource baseResource,
java.lang.String candidateVersion)
Checks whether the given
Resource matches the candidate version string. |
addVersionAsPrefix, addVersionToFilename, deleteVersionAsPrefix, deleteVersionFromFilename, extractVersionAsPrefix, extractVersionFromFilename
public FixedVersionStrategy(java.lang.String fixedVersion)
fixedVersion
- the fixed version string to usepublic FixedVersionStrategy(java.util.concurrent.Callable<java.lang.String> versionInitializer) throws java.lang.Exception
Callable
instance.java.lang.Exception
public java.lang.String extractVersionFromPath(java.lang.String requestPath)
VersionStrategy
requestPath
- the request path of the resource being resolvedpublic java.lang.String deleteVersionFromPath(java.lang.String requestPath, java.lang.String candidateVersion)
VersionStrategy
requestPath
- the request path of the resource being resolvedcandidateVersion
- the candidate version stringpublic boolean resourceVersionMatches(Resource baseResource, java.lang.String candidateVersion)
VersionStrategy
Resource
matches the candidate version string.
Useful when the version string is managed on a per-resource basis.baseResource
- the resource to check against the given versioncandidateVersion
- the candidate version for the given resourcepublic java.lang.String addVersionToUrl(java.lang.String baseUrl, java.util.List<? extends Resource> locations, ResourceResolverChain chain)
VersionStrategy
baseUrl
- the baseUrl of the requested resourcelocations
- the resource locations to resolve resources fromchain
- the chain of resource resolvers