Как включить кэширование статических ресурсов.
Знаю что можно добавить дерективу в application.yml
spring.resources.cache.cachecontrol.max-age: 3600
Но пытаюсь так же реализовать прочие примеры, но они не работают
Файл WebSecurityConfig
@EnableOAuth2Sso
@EnableWebSecurity
@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/", "/login**", "/error**", "/js/**", "/favicon.ico")
.permitAll()
.anyRequest()
.authenticated()
.and()
.logout()
.logoutSuccessUrl("/")
.permitAll()
.and()
.csrf().disable();
// @formatter:on
}
}
Файл: WebMvcConfig
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/resources/**")
.addResourceLocations("/resources/")
.setCachePeriod(31556926)
// или
// .setCacheControl(CacheControl.maxAge(1, TimeUnit.DAYS))
;
}
}
По пути лежит: resources/static/js/bundle.js
λ curl -I http://localhost:9000/js/bundle.js
HTTP/1.1 200
Last-Modified: Sun, 23 Jun 2019 11:37:55 GMT
Cache-Control: no-store
Accept-Ranges: bytes
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
X-Frame-Options: DENY
Content-Type: application/javascript
Content-Length: 1033085
Date: Sun, 23 Jun 2019 11:44:17 GMT