为什么我需要清理缓存才能在我的角度应用程序中看到最新的模块?

问题描述:

我们有一个Angular 10应用程序,每次我们部署到AWS时,甚至在DEV环境中(在ngnix之上),我们都需要清理缓存(CTRL + F5,可以解决此问题).我们已经在Angular项目中尝试了下一个meta标签:

We have an Angular 10 app that everytime we make a deployment to AWS, or even in DEV enviroment(over ngnix) we need to clean cache (CTRL+F5, doing this is solved). We have tried in the Angular project the next meta tags:

<meta http-equiv="cache-control" content="no-cache, must-revalidate, post-check=0, precheck=0">
<meta http-equiv="expires" content="0">
<meta http-equiv="pragma" content="no-cache">

我们尝试过的另一个想法是通过部署交替对文件名进行哈希处理.一次不进行哈希处理,而下一次进行哈希处理.例如:

Another ideas we have tried is alternating hashing the file names by deployment. Once is done without hash, and the next time, with hash. Per example:

6-es5.js -> changes to -> 6-es5.b0d27b410e5c019afd47.js

在AWS S3(通过Amazon Cloudfront)中,我们尝试设置

In AWS S3(Over Amazon Cloudfront) we tried setting up

Minimum TTL 0
Maximum TTL 0
Default TTL 0

我们现在不知道还有什么其他想法可能是可行的,或者我们做错了什么.任何想法都会有所帮助.谢谢大家!

We dont know by now what another ideas could be possible, or what we are doing wrong. Any ideas would be helpful. Thanks guys!

更新

没有像我在所有组件中所说的那样添加元标记.我们已经将它添加到index.html(我们错过了将它们包含在此文件中)的功能,现在它可以按预期运行,但是现在还不确定它是否只是暂时的解决方案.

The meta tags were not added as I said in all the components. We already added it to the index.html(we missed include them in this file) and now it's working as expected, but we are not sure if its just a temporal solution by now.

您可以执行以下步骤:

  1. 直接将构建文件夹部署到S3存储桶.
  2. 不需要缓存 index.html 文件
  3. 每当您将构建部署或上载到S3时,请执行以下步骤
  4. 转到云端
  5. 使对象无效
  6. 创建条目/*

部署脚本

要进行连续部署,您可以使用aws的 boto3 编写脚本,以在文件夹成功上传后自动使缓存无效.

For continuous deployment you can write script using boto3 of aws for automatically invalidate cached once folder uploaded successfully.