angularjs - 如何爆掉 yeoman index.html 缓存

标签 angularjs caching

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

我正在为我的项目使用 Yeoman( generator-gulp-angular )。我看了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 的 header 浏览器将始终获得新副本。现在,Grunt 已经根据内容重命名了 JS 和 CSS 文件,然后它会自动刷新。
当然,上面的例子是针对Nginx的配置。您可以为您的 Web 服务器实现它。

关于angularjs - 如何爆掉 yeoman index.html 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33382690/

相关文章:

javascript - 数据更改时的 angularjs 和 ng-init 作用域

javascript - IIS 8.5 中托管的 AngularJS html5Mode 路由问题

java - 使用 Aerospike bin 名称的最佳做法是什么?

http - 浏览器是否会根据协议(protocol)改变缓存内容?

javascript - Angular Directive(指令) : get input type ="number" value on keypress

javascript - Angular JS : Validate form fields before submit

javascript - 防止appcache缓存当前页面

ASP.NET MVC Html.TextBox刷新问题

javascript - 每个 XHR Angular 请求都会出错

Django : Two ways of caching template : What is the difference?