防止使用spring-boot缓存index.html文件

杰克斯

我正在使用spring-boot,并希望防止缓存index.html,但要缓存所有其他资源,因此我将资源文件放在类路径中,并使用以下命令防止了缓存。

目前,我正在执行以下操作,以缓存所有文件。

@Configuration
public class StaticResourceConfig extends WebMvcConfigurerAdapter {

    private static final int SEVEN_DAYS_IN_SECONDS = 604800;

    @Override
    public void addResourceHandlers(final ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:frontend/dist/")
                .setCachePeriod(SEVEN_DAYS_IN_SECONDS);
        super.addResourceHandlers(registry);
    }

}

index.html文件位于frontend / dist / index.html

杰克斯

我设法做到这一点:

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {

   registry.addResourceHandler("/index.html")
            .addResourceLocations("classpath:frontend/dist/index.html")
            .setCachePeriod(0);

   registry.addResourceHandler("/assets/**")
            .addResourceLocations("classpath:frontend/dist/assets")
            .setCachePeriod(SEVEN_DAYS_IN_SECONDS);

    super.addResourceHandlers(registry);
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章