Package com.vaadin.flow.internal
Class ResourceContentHash
java.lang.Object
com.vaadin.flow.internal.ResourceContentHash
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 Summary
Modifier and TypeMethodDescriptionstatic voidDiscards all cached hashes.static StringgetContentHash(VaadinService service, String resourceUrl) Computes a truncated SHA-256 content hash for the given resource URL.
-
Method Details
-
getContentHash
Computes a truncated SHA-256 content hash for the given resource URL. Returnsnullfor 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 resourceresourceUrl- the resource path to hash- Returns:
- an 8-character hex hash string, or
nullif 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
-