I have tried to add fingerprint suffix to some of my static files (Ex. 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 config the ResourceHandler 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 have add some debug log.
logger.debug("js = '{}'" + this.resourceUrlProvider.getForLookupPath("/build/app.js"));
logger.debug("css = '{}'" + this.resourceUrlProvider.getForLookupPath("/build/styles/style.css"));
After run the web application, from the debug log, there is fingerprint in each file like
app-5d2c76ad6517f26d252d5cc93a4fc7d2.js
and I can access this file directly, (ie. via localhost:8080/build/app-5d2c76ad6517f26d252d5cc93a4fc7d2.js)
However, when I click view source at the web browser, it is still an original file without any fingerprint.
which in my layout.html I load the script/link like this.
<script th:src="@{/build/app.js}"></script>
<link th:href="@{/build/styles/style.css}" rel="stylesheet"></link>
I use Thymeleaf for template engine. What should the configuration or code be to make Thymeleaf include the fingerprint files or did I miss something ?
Thank you very much.