简体   繁体   English

当AngularJS网站内容发生变化时,如何使index.html不缓存?

[英]How to make index.html not to cache when the site contents are changes in AngularJS website?

Normally for .js and .css file we will append a version during build like xx.js?v=123 , and then after website deploy, we can get the new version of js and CSS.通常对于.js.css文件,我们会在构建过程中 append 一个版本,例如xx.js?v=123 ,然后在网站部署后,我们可以得到新版本的 js 和 Z2C56C360580420D293172。 But I don't see a place talking about how to make the index.html file upgrade when website deployment happen.但是我没有看到一个地方谈论如何在网站部署发生时使index.html文件升级。 And we do see in IE that the HTML content should have been changed but it still use the old HTML content.我们确实在 IE 中看到 HTML 内容应该已更改,但它仍使用旧的 HTML 内容。

One solution I find from google is to我从谷歌找到的一种解决方案是

<meta http-equiv="Cache-control" content="no-cache">

However, I am not sure whether this is the best solution?但是,我不确定这是否是最好的解决方案?

Normally for .js and .css file we will append a version during build like xx.js?v=123 , and then after website deploy, we can get the new version of js and CSS.通常对于.js.css文件,我们会在构建时附加一个版本,如xx.js?v=123 ,然后在网站部署后,我们可以获得新版本的 js 和 CSS。 But I don't see a place talking about how to make the index.html file upgrade when website deployment happen.但是我没有看到一个地方谈论如何在网站部署发生时升级index.html文件。 And we do see in IE that the HTML content should have been changed but it still use the old HTML content.我们确实在 IE 中看到 HTML 内容应该已更改,但它仍然使用旧的 HTML 内容。

One solution I find from google is to我从谷歌找到的一种解决方案是

<meta http-equiv="Cache-control" content="no-cache">

However, I am not sure whether this is the best solution?但是,我不确定这是否是最佳解决方案?

Normally for .js and .css file we will append a version during build like xx.js?v=123 , and then after website deploy, we can get the new version of js and CSS.通常对于.js.css文件,我们会在构建时附加一个版本,如xx.js?v=123 ,然后在网站部署后,我们可以获得新版本的 js 和 CSS。 But I don't see a place talking about how to make the index.html file upgrade when website deployment happen.但是我没有看到一个地方谈论如何在网站部署发生时升级index.html文件。 And we do see in IE that the HTML content should have been changed but it still use the old HTML content.我们确实在 IE 中看到 HTML 内容应该已更改,但它仍然使用旧的 HTML 内容。

One solution I find from google is to我从谷歌找到的一种解决方案是

<meta http-equiv="Cache-control" content="no-cache">

However, I am not sure whether this is the best solution?但是,我不确定这是否是最佳解决方案?

Normally for .js and .css file we will append a version during build like xx.js?v=123 , and then after website deploy, we can get the new version of js and CSS.通常对于.js.css文件,我们会在构建时附加一个版本,如xx.js?v=123 ,然后在网站部署后,我们可以获得新版本的 js 和 CSS。 But I don't see a place talking about how to make the index.html file upgrade when website deployment happen.但是我没有看到一个地方谈论如何在网站部署发生时升级index.html文件。 And we do see in IE that the HTML content should have been changed but it still use the old HTML content.我们确实在 IE 中看到 HTML 内容应该已更改,但它仍然使用旧的 HTML 内容。

One solution I find from google is to我从谷歌找到的一种解决方案是

<meta http-equiv="Cache-control" content="no-cache">

However, I am not sure whether this is the best solution?但是,我不确定这是否是最佳解决方案?

Normally for .js and .css file we will append a version during build like xx.js?v=123 , and then after website deploy, we can get the new version of js and CSS.通常对于.js.css文件,我们会在构建时附加一个版本,如xx.js?v=123 ,然后在网站部署后,我们可以获得新版本的 js 和 CSS。 But I don't see a place talking about how to make the index.html file upgrade when website deployment happen.但是我没有看到一个地方谈论如何在网站部署发生时升级index.html文件。 And we do see in IE that the HTML content should have been changed but it still use the old HTML content.我们确实在 IE 中看到 HTML 内容应该已更改,但它仍然使用旧的 HTML 内容。

One solution I find from google is to我从谷歌找到的一种解决方案是

<meta http-equiv="Cache-control" content="no-cache">

However, I am not sure whether this is the best solution?但是,我不确定这是否是最佳解决方案?

Just add this to nginx file:只需将其添加到nginx文件中:

 location ~ \.html$ {
    add_header Cache-Control no-store;
 }

No, this is certainly not the correct way. 不,这肯定不是正确的方法。 Consider a website with more than one page (read: 99.999% of websites) do you seriously believe that the developer should explicitly set no-cache on each page? 考虑一个有多个页面的网站(阅读:99.999%的网站)您是否认真地认为开发人员应该在每个页面上明确设置无缓存? This has nothing whatsoever to do with Angular and everything to do with your web-server (which has no idea what's inside the index.html file) incorrectly caching files as though they were static content. 这与Angular没有任何关系,与你的web服务器(它不知道index.html文件中的内容)有关的一切都不正确地缓存文件,就好像它们是静态内容一样。

Certainly consider no-cache as a temporary measure until you fix your server configuration. 在修复服务器配置之前,请务必将无缓存视为临时措施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM