I have a Spring Boot 2 application where static resources are:
src
|- main
|-resources
|-static
|-js/myjs.js
|-style
|-css/mycss.css
In my template file:
<link rel="stylesheet" type="text/css" href="/style/css/mycss.css">
<script src="/js/myjs.js"></script>
This is working fine.
However I want to enable browser cache and gzip transfer. To do this I have created the following WebConfig:
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/static/**")
.addResourceLocations("/static/")
.setCachePeriod(3600)
.resourceChain(true)
.addResolver(new GzipResourceResolver())
.addResolver(new PathResourceResolver());
}
}
The app still works but no static content is cached nor gzipped:
Any idea what I'm doing wrong?