当网站内容在AngularJS网站中发生更改时,如何使index.html不缓存? [英] How to make index.html not to cache when the site contents are changes in AngularJS website?

查看:123
本文介绍了当网站内容在AngularJS网站中发生更改时,如何使index.html不缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常对于.js.css文件,我们会在构建过程中附加一个版本,例如 xx.js?v=123,然后在网站部署之后,我们可以获得新版本的js和CSS.但是我看不到一个地方谈论如何在部署网站时进行index.html文件升级.而且我们确实在IE中看到应该更改HTML内容,但它仍使用旧的HTML内容.

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.

我从Google找到的一种解决方案是

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?

推荐答案

是的,这是正确的方法.您必须设置Cache-Control标头,以使浏览器知道它们不必为该请求缓存任何内容.

Yes, that is the correct way. You have to set the Cache-Control header to let the browsers know that they don't have to cache any content for that request.

<meta http-equiv="Cache-control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">

(Pragma& Cache-Control是一回事,但来自不同的HTTP规范.请参见此处的答案:

(Pragma & Cache-Control is one and the same thing but from the different HTTP specification. See the answer here: Difference between Pragma and Cache-control headers?)

在此处查看相关答案之一:如何爆发yeoman index.html缓存

See one of the related answer here: How to burst yeoman index.html cache

这篇关于当网站内容在AngularJS网站中发生更改时,如何使index.html不缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆