springboot 静态资源缓存设置

时间:2024-05-23 14:10:35

springboot 静态资源 js css  缓存设置

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
            .addResourceHandler("/resources/**")
            .addResourceLocations("/resources/")
            .setCachePeriod(31556926);

        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("/webjars/")
                .setCachePeriod(31556926);
    }


}
<script src="/webjars/ueditor/ueditor.all.min.js"></script>

springboot 静态资源缓存设置

https://docs.spring.io/spring-security/site/docs/5.1.2.RELEASE/reference/htmlsingle/#headers-cache-control