Class StylesheetContentHashUtil

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

public class StylesheetContentHashUtil extends Object
Computes and caches content-based hashes for stylesheet resources, enabling cache-busting by appending ?v-c=<hash> to stylesheet 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.

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
    • appendHashToUrl

      public static String appendHashToUrl(String url, String hash)
      Appends a version query parameter to the given URL using the provided hash. Returns the original URL unchanged if the hash is null.
      Parameters:
      url - the original URL
      hash - the content hash, or null
      Returns:
      the URL with ?v-c=<hash> or &v-c=<hash> appended, or the original URL if hash is null