This dialect offers an attribute to handle versioning of HTML resource (js, css) for cache busting purposes.
Just add this dialect to the Thymelaf engine, passing the desired version as a constructor parameter.
final TemplateEngine engine = new TemplateEngine();
engine.setDialects(Arrays.asList(
...
new VersionedResourceDialect(version),
...
));Add a version:append attribute to any tag with a src/href attribute to append a version query parameter:
<script type="text/javascript" src="/path/to/resource.js" version:append></script>will be rendered as
<script type="text/javascript" src="/path/to/resource.js?version=xxxx"></script>Notes:
- if a query string is already present the version parameter will be concatenated using &
- an already present
versionparameter will not be overridden - empty
src/hrefattributes will not be updated