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

查看:22
本文介绍了当 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.

我从谷歌找到的一个解决方案是

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 标头之间的区别?)

(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天全站免登陆