java - 无法使用 Springboot 对静态文件进行版本控制(缓存破坏)
问题描述
我有时会遇到问题,即浏览器使用一些旧的 javascript 文件,即使对文件进行了修改。在开发期间它从未发生过,但在服务器(生产)上它确实发生了。
hier 是我的 application.properties
server.servlet.context-path=/mrr-cms
server.port=8050
spring.cache.type=NONE
spring.resources.chain.cache=false
#Authorization/Licensing (AM/LM)
service.permission.url=https://datlx107
service.permission.endpoint=/AuthorizationManager/service--/endpoint/permissionService
#JWT Token authentication service
service.token.endpoint=/AuthorizationManager/service--/endpoint/tokenService
# Neues Produkt MRR_CMS in der LM/AM Datenbank
service.permission.productName=MRR_CMS
所有其他配置都是 Spring boot 的默认配置。我没有覆盖任何类,例如@config
解决方案
您可以创建配置来为静态资源设置自己的缓存设置。
@Configuration
public class CacheWebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/")
.setCacheControl(CacheControl.maxAge(60, TimeUnit.SECONDS)
.noTransform()
.mustRevalidate());
}
}
请参阅本教程。
推荐阅读
- assembly - 我应该在固件中填写多少异常向量?
- javascript - Puppeteer TimeoutError:超过 30000 毫秒的导航超时
- dompdf - Laravel 6 barryvdh / laravel-dompdf 渲染问题
- javascript - 从 webapp 深度链接到 Google Pay 等 UPI 应用
- django - 仅当值存在于另一个表中时,我如何返回 Django 查询集?
- java - 可以在 webDriver 的不同端口使用当前会话吗?
- c# - Linq 函数的传统 sql 等效项
- kubernetes - Kubelet REST API 确定什么是容器运行时及其版本
- python - 使用哈希时发现 x 的代码是否正确?
- ubuntu - org.apache.hadoop.security.AccessControlException):权限被拒绝: