Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 如何中断yeoman index.html缓存_Angularjs_Caching - Fatal编程技术网

Angularjs 如何中断yeoman index.html缓存

Angularjs 如何中断yeoman index.html缓存,angularjs,caching,Angularjs,Caching,当我部署Angular应用程序的新版本时,旧版本仍然存在。只是,正在修复的解决方法是在浏览器上进行“硬”刷新。(这不是一个可接受的解决方案) 我在我的项目中使用Yeoman(发电机角度)。我查看了Gruntfile.js,看到它执行了一项任务,在构建过程中重命名所有内容,包括图像、js和css。唯一不被重命名的文件是index.html。如何处理index.html,以便浏览器加载此文件而不是使用缓存版本 您可以在服务器配置中修改,通过设置响应的cache和Expires头来告诉浏览器不要缓存。

当我部署Angular应用程序的新版本时,旧版本仍然存在。只是,正在修复的解决方法是在浏览器上进行“硬”刷新。(这不是一个可接受的解决方案)


我在我的项目中使用Yeoman(发电机角度)。我查看了
Gruntfile.js
,看到它执行了一项任务,在构建过程中重命名所有内容,包括图像、js和css。唯一不被重命名的文件是
index.html
。如何处理
index.html
,以便浏览器加载此文件而不是使用缓存版本

您可以在服务器配置中修改,通过设置响应的
cache
Expires
头来告诉浏览器不要缓存。我给大家举一个Nginx的例子:

location / {
    index index.html
    expires -1;
    add_header Pragma "no-cache";
    add_header Cache-Control "no-store"
}
在这里,我们使用头来响应
index.html
,这将阻止浏览器缓存
index.html
,并且浏览器将始终获得新副本。现在,Grunt已经基于内容重命名了JS和CSS文件,然后它将自动刷新


当然,上面的示例是针对
Nginx
配置的。您可以在web服务器上实现这一点。

您能解决这个问题吗?