Class ResourceContentHash

java.lang.Object
com.vaadin.flow.internal.ResourceContentHash

public class ResourceContentHash extends Object
Computes and caches content-based hashes for static resources, enabling cache-busting by appending a version query parameter to resource URLs. The hash changes only when file content changes, allowing aggressive browser caching.

For internal use only. May be renamed or removed in a future release.

Since:
25.1
Author:
Vaadin Ltd
  • Method Details

    • getContentHash

      public static String getContentHash(VaadinService service, String resourceUrl)
      Computes a truncated SHA-256 content hash for the given resource URL. Returns null for external URLs (http/https), missing resources, or on any I/O error. Results are cached so that each resource is read at most once.
      Parameters:
      service - the Vaadin service used to load the resource
      resourceUrl - the resource path to hash
      Returns:
      an 8-character hex hash string, or null if the hash cannot be computed
    • clearCache

      public static void clearCache()
      Discards all cached hashes.

      The cache is static and keyed by resource path only, so it outlives the service that filled it. Tests that assert on hashed URLs need to reset it to avoid observing a hash computed for the same path by another test.

      Since:
      25.2.9