如何爆自耕农的index.html缓存 [英] How to burst yeoman index.html cache

查看:95
本文介绍了如何爆自耕农的index.html缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我部署我的角度应用程序的新版本,旧版本仍然存在。只是,这是固定的解决方法是在浏览器中的硬刷新。 (这是不能接受的解决方案)。

When I deploy a new version of my Angular app, the old version still persist. Only, the workaround which is fixing is a "hard" refresh on the browser. (This is not an acceptable solution).

我使用的约曼(发电机角)为我的项目。我看了看 Gruntfile.js ,并认为它会执行构建包括图片,JS,CSS中重命名一切的任务。只有文件不被重命名为 index.html的。我能做些什么来 index.html的使浏览器反而会加载使用缓存版本的这个文件?

I am using Yeoman (generator-angular) for my project. I looked at the Gruntfile.js and see that it executes a task that renames everything during build including images, js, css. Only file that is not being renamed is index.html. What can I do to index.html so that browser will load this file instead of using the cached version?

推荐答案

您可以在您的服务器配置修改,告诉浏览器没有设置高速缓存缓存过期头的响应。我给你的Nginx的例子:

You can modify in your server config to tell browsers to not cache by setting Cache and Expires header for response. I'm giving you an example of Nginx:

location / {
    index index.html
    expires -1;
    add_header Pragma "no-cache";
    add_header Cache-Control "no-cache, no-store, must-revalidate"
}

在这里,我们响应 index.html的用头将美元的缓存 index.html的和浏览器总是会得到新的副本。现在,咕噜已重命名基于内容然后它会自动刷新的JS和CSS文件。

Here we are responding index.html with headers which will prevent browsers from caching the index.html and the browsers will always get the fresh copy. Now, Grunt is already renaming the JS and CSS files based on the content then it will be refreshed automatically.

当然,上面的例子是 Nginx的配置。你可以实现它为您的Web服务器。

Of course, above example is for Nginx configuration. You can achieve it for your web server.

这篇关于如何爆自耕农的index.html缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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