diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java index ca5bd89b78e1..461d72dec4a2 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java @@ -30,8 +30,8 @@ * 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 {@code }. - * This path will be resolved to the unique version {@code }, + * like {@code }. + * This path will be resolved to the unique version {@code }, * which is a better fit for HTTP caching and version management in applications. * *
This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}. @@ -39,6 +39,9 @@ *
This resolver requires the {@code org.webjars:webjars-locator-core} library * on the classpath and is automatically registered if that library is present. * + *
Be aware that {@code WebJarAssetLocator} constructor performs a classpath scanning that + * could slow down application startup. + * * @author Rossen Stoyanchev * @author Brian Clozel * @since 5.0 diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java index d7dbb15cd16a..1b55b5bb0b75 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java @@ -29,8 +29,8 @@ * 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 {@code }. - * This path will be resolved to the unique version {@code }, + * like {@code }. + * This path will be resolved to the unique version {@code }, * which is a better fit for HTTP caching and version management in applications. * *
This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}. @@ -38,6 +38,9 @@ *
This resolver requires the {@code org.webjars:webjars-locator-core} library * on the classpath and is automatically registered if that library is present. * + *
Be aware that {@code WebJarAssetLocator} constructor performs a classpath scanning that + * could slow down application startup. + * * @author Brian Clozel * @since 4.2 * @see org.springframework.web.servlet.config.annotation.ResourceChainRegistration diff --git a/src/docs/asciidoc/web/webflux.adoc b/src/docs/asciidoc/web/webflux.adoc index 4f4aeb3e4c5a..1ead716f3dce 100644 --- a/src/docs/asciidoc/web/webflux.adoc +++ b/src/docs/asciidoc/web/webflux.adoc @@ -4498,12 +4498,18 @@ Note that, when using both `EncodedResourceResolver` (for example, Gzip, Brotli `VersionedResourceResolver`, they must be registered in that order, to ensure content-based versions are always computed reliably based on the unencoded file. -https://www.webjars.org/documentation[WebJars] are also supported through the +For https://www.webjars.org/documentation[WebJars], versioned URLs like +`/webjars/jquery/1.2.0/jquery.min.js` are the recommended and most efficient way to use them. +The related resource location is configured out of the box with Spring Boot (or can be configured +manually via `ResourceHandlerRegistry`) and does not require to add the +`org.webjars:webjars-locator-core` dependency. + +Version-less URLs like `/webjars/jquery/jquery.min.js` are supported through the `WebJarsResourceResolver` which is automatically registered when the -`org.webjars:webjars-locator-core` library is present on the classpath. The resolver can -re-write URLs to include the version of the jar and can also match against incoming URLs -without versions -- for example, from `/jquery/jquery.min.js` to -`/jquery/1.2.0/jquery.min.js`. +`org.webjars:webjars-locator-core` library is present on the classpath, at the cost of a +classpath scanning that could slow down application startup. The resolver can re-write URLs to +include the version of the jar and can also match against incoming URLs without versions +-- for example, from `/webjars/jquery/jquery.min.js` to `/webjars/jquery/1.2.0/jquery.min.js`. TIP: The Java configuration based on `ResourceHandlerRegistry` provides further options for fine-grained control, e.g. last-modified behavior and optimized resource resolution. diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index 9d3c211214f6..3c64109569ab 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -6104,12 +6104,18 @@ Note that, when using both `EncodedResourceResolver` (for example, for serving g brotli-encoded resources) and `VersionResourceResolver`, you must register them in this order. That ensures content-based versions are always computed reliably, based on the unencoded file. -https://www.webjars.org/documentation[WebJars] are also supported through the +For https://www.webjars.org/documentation[WebJars], versioned URLs like +`/webjars/jquery/1.2.0/jquery.min.js` are the recommended and most efficient way to use them. +The related resource location is configured out of the box with Spring Boot (or can be configured +manually via `ResourceHandlerRegistry`) and does not require to add the +`org.webjars:webjars-locator-core` dependency. + +Version-less URLs like `/webjars/jquery/jquery.min.js` are supported through the `WebJarsResourceResolver` which is automatically registered when the -`org.webjars:webjars-locator-core` library is present on the classpath. The resolver can -re-write URLs to include the version of the jar and can also match against incoming URLs -without versions -- for example, from `/jquery/jquery.min.js` to -`/jquery/1.2.0/jquery.min.js`. +`org.webjars:webjars-locator-core` library is present on the classpath, at the cost of a +classpath scanning that could slow down application startup. The resolver can re-write URLs to +include the version of the jar and can also match against incoming URLs without versions +-- for example, from `/webjars/jquery/jquery.min.js` to `/webjars/jquery/1.2.0/jquery.min.js`. TIP: The Java configuration based on `ResourceHandlerRegistry` provides further options for fine-grained control, e.g. last-modified behavior and optimized resource resolution.