由于我们的团队现在正在运行快速更新,因此我的角度应用程序正在不断变化。缓存我们的客户并不总是拥有我们代码的最新版本。
所以在 angular 中有一种方法可以强制浏览器清除缓存?
解决方案您可以使用一个非常简单的解决方案,即在脚本文件中附加散列。每次部署您的应用程序时,您都会通过gulp / grunt任务自动为您的文件提供不同的散列。作为示例,您可以使用 gulp-rev 。我在我的所有项目中都使用这种技术,并且工作得很好,在您的构建/部署过程中自动化可以成为您所有项目的解决方案。
Yeoman发生器用于AngularJS 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强制浏览器清除缓存
发布评论