Skip to content

LiteWebJarsResourceResolver does not resolve directories #36726

Closed

Description

@Chr3is

I have a Thymeleaf template which has something like this:

<script id="tesseract-config" type="application/json" th:inline="text">
    {
        "workerPath":"[[@{/webjars/frontend/tesseract/worker/worker.min.js}]]",
        "corePath":"[[@{/webjars/frontend/tesseract/core/__${tesseractCore}__}]]",
        "langPath":"[[@{/webjars/frontend/tesseract/lang/}]]"
    }
</script>

this template is resolved to

<script id="tesseract-config" type="application/json">
      {
          "workerPath":"/webjars/frontend/1.0.60/tesseract/worker/worker.min.js",
          "corePath":"/webjars/frontend/1.0.60/tesseract/core/tesseract-core-lstm.wasm.js",
          "langPath":"/webjars/frontend/tesseract/lang/"
      }
</script>

My problem is, that the webjars path is only resolved to the correct version, where a resource was specified. Directories do not get resolved.

The issue seems to be here: https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/LiteWebJarsResourceResolver.java#L77

the resolver returns null and the original path is returned instead of the webJarResourcePath. In this concrete example, the resolver returns null because the directory is not "readable" but exists https://github.com/spring-projects/spring-framework/blob/main/spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java#L189

That's an issue for us, because the browser requests unversioned files due to the unversioned directory, which get cached due to the cache control header.

Activity

  1. added
    in: webIssues in web modules (web, webmvc, webflux, websocket)
    on Apr 29, 2026
  2. AtharvUrunkar commented on Apr 29, 2026

    @AtharvUrunkar

    This appears to be a limitation in LiteWebJarsResourceResolver where only file resources are resolved to versioned paths, while directory paths are not.

    From the current flow:

    • Directory paths (e.g. /webjars/.../lang/) are passed down to PathResourceResolver
    • Since directories are not considered "readable" resources, resolution returns null
    • As a result, the original (unversioned) path is preserved

    This leads to inconsistent behavior:

    • File paths → correctly versioned
    • Directory paths → remain unversioned

    In our case, this causes issues with caching because browsers cache unversioned directory-based requests, which can result in stale assets after upgrades.

    It would be helpful if the resolver could:

    • Either resolve directory paths to their versioned equivalents, or
    • Provide a documented way to obtain versioned base paths for WebJars

    Happy to help explore a fix if this behavior is considered unintended.

  3. self-assigned this
    on Apr 30, 2026
  4. added and removed on Apr 30, 2026
  5. added this to the 7.0.8 milestone on Apr 30, 2026
  6. added 2 commits that reference this issue on Apr 30, 2026
    910117e
    3a91d90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions