重新部署webapp缩小后的404错误(缓存)

时间:2016-02-25 12:01:00

标签: css angularjs spring browser-cache

我正面临着我的webapp的问题:每次我必须重新部署它(AWS)时,页面第一次都无法正确加载,因为(我相信)本地缓存有js和先前部署对应的css个文件。我使用Java备份的Angular并使用Spring Boot服务。

This is the state the page looks like

当我重新下载(例如Ctrl + R)时,一切正常。为了解决这个问题,我在index.html中添加了以下元数据:

<!--Setting the content to "0" tells the browsers to always load the page from the web server.-->
  <meta http-equiv="cache-control" content="max-age=0"/>
  <meta http-equiv="cache-control" content="no-cache"/>
  <meta http-equiv="expires" content="0"/>
  <meta http-equiv="expires" content="0"/>
  <meta http-equiv="pragma" content="no-cache"/>

哪个显然不起作用。我该怎么办?

3 个答案:

答案 0 :(得分:4)

也许你可以通过向文件添加查询来欺骗这种行为,有些想法如下:

<script src="myscript.js?build=mybuildversion"></script>
<link href="mystyles.css?build=mybuildversion" rel="stylesheet">

答案 1 :(得分:0)

您无需指示浏览器不清除index.html文件的缓存。而是它的CSS文件正在缓存。但是,建议不要清除静态资源(如图像或css文件)的缓存。相反,这些文件应该长时间缓存以节省带宽。如果要强制浏览器获取最新版本的静态资源,则需要使用Spring VersionResourceResolver策略。 https://dzone.com/articles/2-step-resource-versioning-with-spring-mvchttp://www.slideshare.net/rstoya05/resource-handling-spring-framework-41

答案 2 :(得分:0)

我同意@Rogerio Soares - 你的缩小脚本应该包含它们经历的每次迭代的唯一标识符,无论是在文件名中还是在路径/ url附带的查询字符串中。这可以在grunt / gulp构建过程中处理。