Skip to content

Commit 1439c5b

Browse files
committed
Document how to use WebJars without webjars-locator-core dependency
Closes gh-29322
1 parent 3f42d4d commit 1439c5b

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/resource/WebJarsResourceResolver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@
3030
* attempts to find a matching versioned resource contained in a WebJar JAR file.
3131
*
3232
* <p>This allows WebJars.org users to write version agnostic paths in their templates,
33-
* like {@code <script src="/jquery/jquery.min.js"/>}.
34-
* This path will be resolved to the unique version {@code <script src="/jquery/1.2.0/jquery.min.js"/>},
33+
* like {@code <script src="/webjars/jquery/jquery.min.js"/>}.
34+
* This path will be resolved to the unique version {@code <script src="/webjars/jquery/1.2.0/jquery.min.js"/>},
3535
* which is a better fit for HTTP caching and version management in applications.
3636
*
3737
* <p>This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}.
3838
*
3939
* <p>This resolver requires the {@code org.webjars:webjars-locator-core} library
4040
* on the classpath and is automatically registered if that library is present.
4141
*
42+
* <p>Be aware that {@code WebJarAssetLocator} constructor performs a classpath scanning that
43+
* could slow down application startup.
44+
*
4245
* @author Rossen Stoyanchev
4346
* @author Brian Clozel
4447
* @since 5.0

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@
3030
* attempts to find a matching versioned resource contained in a WebJar JAR file.
3131
*
3232
* <p>This allows WebJars.org users to write version agnostic paths in their templates,
33-
* like {@code <script src="/jquery/jquery.min.js"/>}.
34-
* This path will be resolved to the unique version {@code <script src="/jquery/1.2.0/jquery.min.js"/>},
33+
* like {@code <script src="/webjars/jquery/jquery.min.js"/>}.
34+
* This path will be resolved to the unique version {@code <script src="/webjars/jquery/1.2.0/jquery.min.js"/>},
3535
* which is a better fit for HTTP caching and version management in applications.
3636
*
3737
* <p>This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}.
3838
*
3939
* <p>This resolver requires the {@code org.webjars:webjars-locator-core} library
4040
* on the classpath and is automatically registered if that library is present.
4141
*
42+
* <p>Be aware that {@code WebJarAssetLocator} constructor performs a classpath scanning that
43+
* could slow down application startup.
44+
*
4245
* @author Brian Clozel
4346
* @since 4.2
4447
* @see org.springframework.web.servlet.config.annotation.ResourceChainRegistration

src/docs/asciidoc/web/webflux.adoc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4256,12 +4256,18 @@ Note that, when using both `EncodedResourceResolver` (for example, Gzip, Brotli
42564256
`VersionedResourceResolver`, they must be registered in that order, to ensure content-based
42574257
versions are always computed reliably based on the unencoded file.
42584258

4259-
https://www.webjars.org/documentation[WebJars] are also supported through the
4259+
For https://www.webjars.org/documentation[WebJars], versioned URLs like
4260+
`/webjars/jquery/1.2.0/jquery.min.js` are the recommended and most efficient way to use them.
4261+
The related resource location is configured out of the box with Spring Boot (or can be configured
4262+
manually via `ResourceHandlerRegistry`) and does not require to add the
4263+
`org.webjars:webjars-locator-core` dependency.
4264+
4265+
Version-less URLs like `/webjars/jquery/jquery.min.js` are supported through the
42604266
`WebJarsResourceResolver` which is automatically registered when the
4261-
`org.webjars:webjars-locator-core` library is present on the classpath. The resolver can
4262-
re-write URLs to include the version of the jar and can also match against incoming URLs
4263-
without versions -- for example, from `/jquery/jquery.min.js` to
4264-
`/jquery/1.2.0/jquery.min.js`.
4267+
`org.webjars:webjars-locator-core` library is present on the classpath, at the cost of a
4268+
classpath scanning that could slow down application startup. The resolver can re-write URLs to
4269+
include the version of the jar and can also match against incoming URLs without versions
4270+
-- for example, from `/webjars/jquery/jquery.min.js` to `/webjars/jquery/1.2.0/jquery.min.js`.
42654271

42664272
TIP: The Java configuration based on `ResourceHandlerRegistry` provides further options
42674273
for fine-grained control, e.g. last-modified behavior and optimized resource resolution.

src/docs/asciidoc/web/webmvc.adoc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5870,12 +5870,18 @@ Note that, when using both `EncodedResourceResolver` (for example, for serving g
58705870
brotli-encoded resources) and `VersionResourceResolver`, you must register them in this order.
58715871
That ensures content-based versions are always computed reliably, based on the unencoded file.
58725872

5873-
https://www.webjars.org/documentation[WebJars] are also supported through the
5873+
For https://www.webjars.org/documentation[WebJars], versioned URLs like
5874+
`/webjars/jquery/1.2.0/jquery.min.js` are the recommended and most efficient way to use them.
5875+
The related resource location is configured out of the box with Spring Boot (or can be configured
5876+
manually via `ResourceHandlerRegistry`) and does not require to add the
5877+
`org.webjars:webjars-locator-core` dependency.
5878+
5879+
Version-less URLs like `/webjars/jquery/jquery.min.js` are supported through the
58745880
`WebJarsResourceResolver` which is automatically registered when the
5875-
`org.webjars:webjars-locator-core` library is present on the classpath. The resolver can
5876-
re-write URLs to include the version of the jar and can also match against incoming URLs
5877-
without versions -- for example, from `/jquery/jquery.min.js` to
5878-
`/jquery/1.2.0/jquery.min.js`.
5881+
`org.webjars:webjars-locator-core` library is present on the classpath, at the cost of a
5882+
classpath scanning that could slow down application startup. The resolver can re-write URLs to
5883+
include the version of the jar and can also match against incoming URLs without versions
5884+
-- for example, from `/webjars/jquery/jquery.min.js` to `/webjars/jquery/1.2.0/jquery.min.js`.
58795885

58805886
TIP: The Java configuration based on `ResourceHandlerRegistry` provides further options
58815887
for fine-grained control, e.g. last-modified behavior and optimized resource resolution.

0 commit comments

Comments
 (0)