|
9 | 9 | import org.springframework.http.MediaType;
|
10 | 10 | import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
11 | 11 | import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
| 12 | +import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; |
12 | 13 | import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
13 | 14 |
|
14 | 15 | import java.util.List;
|
@@ -37,4 +38,21 @@ public void customize(TomcatServletWebServerFactory factory) {
|
37 | 38 | mappings.add("html", "text/html;charset=utf-8");
|
38 | 39 | factory.setMimeMappings(mappings );
|
39 | 40 | }
|
| 41 | + |
| 42 | + @Override |
| 43 | + public void addResourceHandlers(ResourceHandlerRegistry registry) { |
| 44 | + // 10 days |
| 45 | + addCacheControl(registry, "img", 864000); |
| 46 | + addCacheControl(registry, "vendor", 864000); |
| 47 | + // 1 day |
| 48 | + addCacheControl(registry, "scripts", 86400); |
| 49 | + addCacheControl(registry, "styles", 86400); |
| 50 | + addCacheControl(registry, "views", 86400); |
| 51 | + } |
| 52 | + |
| 53 | + private void addCacheControl(ResourceHandlerRegistry registry, String folder, int cachePeriod) { |
| 54 | + registry.addResourceHandler(String.format("/%s/**", folder)) |
| 55 | + .addResourceLocations(String.format("classpath:/static/%s/", folder)) |
| 56 | + .setCachePeriod(cachePeriod); |
| 57 | + } |
40 | 58 | }
|
0 commit comments