简体   繁体   中英

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. But I don't see a place talking about how to make the index.html file upgrade when website deployment happen. And we do see in IE that the HTML content should have been changed but it still use the old HTML content.

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. But I don't see a place talking about how to make the index.html file upgrade when website deployment happen. And we do see in IE that the HTML content should have been changed but it still use the old HTML content.

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. But I don't see a place talking about how to make the index.html file upgrade when website deployment happen. And we do see in IE that the HTML content should have been changed but it still use the old HTML content.

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. But I don't see a place talking about how to make the index.html file upgrade when website deployment happen. And we do see in IE that the HTML content should have been changed but it still use the old HTML content.

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. But I don't see a place talking about how to make the index.html file upgrade when website deployment happen. And we do see in IE that the HTML content should have been changed but it still use the old HTML content.

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:

 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? 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.

Certainly consider no-cache as a temporary measure until you fix your server configuration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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