AngularJs 强制浏览器清除缓存 [英] AngularJs force browser to clear cache

查看:45
本文介绍了AngularJs 强制浏览器清除缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 angular 应用程序最近在不断变化,因为我们的团队现在运行快速更新.

My angular application is constantly changing these days because our team runs rapid updates right now.

由于缓存,我们的客户端并不总是拥有最新版本的代码.

Because of cache our clients does not always have the newest version of our code.

那么angular有没有办法强制浏览器清除缓存?

So is there a way in angular to force the browser to clear cache?

推荐答案

您可以使用一个非常简单的解决方案,即在您的脚本文件中附加一个哈希值.每次部署您的应用程序时,您都会通过 gulp/grunt 任务自动为您的文件提供不同的哈希值.例如,您可以使用 gulp-rev.我在我的所有项目中都使用了这种技术并且效果很好,在您的构建/部署过程中自动化可以成为您所有项目的解决方案.

You can use a very simple solution that consist in append a hash to your scripts files. Each time your App is deployed you serve your files with a different hash automatically via a gulp/grunt task. As an example you can use gulp-rev. I use this technique in all my projects and works just fine, this automatized in your build/deploy process can be a solution for all your projects.

AngularJS 的 Yeoman 生成器 generator-gulp-angular (这是我的选择的生成器) 使用此解决方案可确保浏览器加载新的优化文件,而不是缓存中的旧文件.请创建一个演示项目并使用它,您将看到它的实际效果.

Yeoman generator for AngularJS generator-gulp-angular (this was my generator of choice) use this solution to ensure that the browser load the new optimazed file and not the old one in cache. Please create a demo project and play with it and you will see it in action.

这篇关于AngularJs 强制浏览器清除缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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