I tried to add a fingerprint suffix to some of my static files (example. App.min.js / style.min.css) using ResourceResolvers and ResourceTransformers http://spring.io/blog/2014/07/24/spring-framework -4-1-handling-static-web-resources
I have a configHandler like this
@Configuration @EnableWebMvc public class ResourceResolverConfiguration extends WebMvcConfigurerAdapter { @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("bower_components/**/*.js", "/assets/**", "/build/**") .addResourceLocations("/bower_components/", "/assets/", "/build/","classpath:/META-INF/webapp/build/") .resourceChain(true) .addResolver( new VersionResourceResolver() .addContentVersionStrategy("/**") ); } }
and in my main controller I add a debug log.
logger.debug("js = '{}'" + this.resourceUrlProvider.getForLookupPath("/build/app.js")); logger.debug("css = '{}'" + this.resourceUrlProvider.getForLookupPath("/build/styles/style.css"));
After starting the web application from the debug log, there is a fingerprint in each file, for example
application-5d2c76ad6517f26d252d5cc93a4fc7d2.js
and I can access this file directly (for example, through localhost: 8080 / build / app-5d2c76ad6517f26d252d5cc93a4fc7d2.js)
However, when I click the view source in a web browser, it is still the source file without any fingerprints.
which in my layout.html I load a script / link like this.
<script th:src="@{/build/app.js}"></script> <link th:href="@{/build/styles/style.css}" rel="stylesheet"></link>
I am using Thymeleaf for the template engine. What should the configuration or code be for Thymeleaf to include fingerprint files or am I missing something?
Many thanks.
java spring thymeleaf
heartmon
source share