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

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

问题描述



由于我们的团队现在正在运行快速更新,因此我的角度应用程序正在不断变化。缓存我们的客户并不总是拥有我们代码的最新版本。



所以在 angular 中有一种方法可以强制浏览器清除缓存?

解决方案

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



Yeoman发生器用于AngularJS <一个href =https://github.com/Swiip/generator-gulp-angular =noreferrer> generator-gulp-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.

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

解决方案

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.

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