I use spring boot 3 and thymeleaf
I would like to cache css, js and img
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/js/**", "/resources/css/**", "/resources/img/**")
.addResourceLocations("/resources/js/", "/resources/css/", "/resources/img/")
.setCacheControl(CacheControl.maxAge(365, TimeUnit.DAYS));
}
}
I tried with
@EnableWebMvc
@Configuration
but get a 404
only
@Configuration
doesn't cache
Can you please try something like this?
Also, recent versions of SpringBoot has certain
propertiesfor managing this:You may try using any of the above
propertiesto achieve your solution.