spring-framework / org.springframework.web.reactive.resource

Package org.springframework.web.reactive.resource

Types

AbstractFileNameVersionStrategy

abstract class AbstractFileNameVersionStrategy : VersionStrategy

Abstract base class for filename suffix based VersionStrategy implementations, e.g. "static/myresource-version.js"

AppCacheManifestTransformer

open class AppCacheManifestTransformer : ResourceTransformerSupport

A ResourceTransformer HTML5 AppCache manifests.

This transformer:

  • modifies links to match the public URL paths that should be exposed to clients, using configured ResourceResolver strategies
  • appends a comment in the manifest, containing a Hash (e.g. "# Hash: 9de0f09ed7caf84e885f1f0f11c7e326"), thus changing the content of the manifest in order to trigger an appcache reload in the browser.

All files with an ".appcache" file extension (or the extension given to the constructor) will be transformed by this class. The hash is computed using the content of the appcache manifest so that changes in the manifest should invalidate the browser cache. This should also work with changes in referenced resources whose links are also versioned.

CachingResourceResolver

open class CachingResourceResolver : AbstractResourceResolver

A ResourceResolver that resolves resources from a Cache or otherwise delegates to the resolver chain and caches the result.

CachingResourceTransformer

open class CachingResourceTransformer : ResourceTransformer

A ResourceTransformer that checks a Cache to see if a previously transformed resource exists in the cache and returns it if found, or otherwise delegates to the resolver chain and caches the result.

ContentVersionStrategy

open class ContentVersionStrategy : AbstractFileNameVersionStrategy

A VersionStrategy that calculates an Hex MD5 hashes from the content of the resource and appends it to the file name, e.g. "styles/main-e36d2e05253c6c7085a91522ce43a0b4.css".

CssLinkResourceTransformer

open class CssLinkResourceTransformer : ResourceTransformerSupport

A ResourceTransformer implementation that modifies links in a CSS file to match the public URL paths that should be exposed to clients (e.g. with an MD5 content-based hash inserted in the URL).

The implementation looks for links in CSS @import statements and also inside CSS url() functions. All links are then passed through the ResourceResolverChain and resolved relative to the location of the containing CSS file. If successfully resolved, the link is modified, otherwise the original link is preserved.

FixedVersionStrategy

open class FixedVersionStrategy : AbstractPrefixVersionStrategy

A VersionStrategy that relies on a fixed version applied as a request path prefix, e.g. reduced SHA, version name, release date, etc.

This is useful for example when ContentVersionStrategy cannot be used such as when using JavaScript module loaders which are in charge of loading the JavaScript resources and need to know their relative paths.

GzipResourceResolver

open class GzipResourceResolver : AbstractResourceResolver

A ResourceResolver that delegates to the chain to locate a resource and then attempts to find a variation with the ".gz" extension.

The resolver gets involved only if the "Accept-Encoding" request header contains the value "gzip" indicating the client accepts gzipped responses.

HttpResource

interface HttpResource : Resource

Extended interface for a Resource to be written to an HTTP response.

PathResourceResolver

open class PathResourceResolver : AbstractResourceResolver

A simple ResourceResolver that tries to find a resource under the given locations matching to the request path.

This resolver does not delegate to the ResourceResolverChain and is expected to be configured at the end in a chain of resolvers.

ResourceResolverChain

interface ResourceResolverChain

A contract for invoking a chain of ResourceResolvers where each resolver is given a reference to the chain allowing it to delegate when necessary.

ResourceTransformer

interface ResourceTransformer

An abstraction for transforming the content of a resource.

TransformedResource

open class TransformedResource : ByteArrayResource

An extension of ByteArrayResource that a ResourceTransformer can use to represent an original resource preserving all other information except the content.

VersionResourceResolver

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.

VersionStrategy

interface VersionStrategy

A strategy to determine the version of a static resource and to apply and/or extract it from the URL path.

WebJarsResourceResolver

open class WebJarsResourceResolver : AbstractResourceResolver

A ResourceResolver that delegates to the chain to locate a resource and then attempts to find a matching versioned resource contained in a WebJar JAR file.

This allows WebJars.org users to write version agnostic paths in their templates, like <script src="/jquery/jquery.min.js"/>. This path will be resolved to the unique version <script src="/jquery/1.2.0/jquery.min.js"/>, which is a better fit for HTTP caching and version management in applications.

This also resolves resources for version agnostic HTTP requests "GET /jquery/jquery.min.js".

This resolver requires the "org.webjars:webjars-locator" library on classpath, and is automatically registered if that library is present.