这是模板缓存中的角破坏的好方法? [英] Is this a good method for template cache busting in angular?

查看:167
本文介绍了这是模板缓存中的角破坏的好方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现某种缓存的方式对我的角度破坏应用程序,它仍然会允许缓存,但打破它随时都推新code生产。我的设置到目前为止,包括使用咕噜缓存断路器 https://www.npmjs.org/package /咕噜缓存断路器通过我串连角app.js文件挖掘和查询参数追加到一个.html文件扩展名结尾的​​字符串。我也做任何模板文件我有一个使用的是NG-包括。一个复杂这将创建的是,现在我需要首先我的模板文件复制到DIST /目录中,所以我可以放心的.gitignore缓存,破获版本,而不必提交所有的我的模板每次缓存捣毁(并会产生冲突)

I'm trying to implement some cache busting on my angular application in a way that it will still allow caching but break it anytime we push new code to production. My setup so far involves using grunt cache-breaker https://www.npmjs.org/package/grunt-cache-breaker to dig through my concatenated angular app.js file and append query params to any string ending in a .html file extension. I also do this for any template files I have that are using an ng-include. One complication this creates is that now I need to first copy my template files to a dist/ directory so I can safely .gitignore the cache-busted versions and not have to commit all of my templates everytime the cache is busted (and create conflicts).

我的问题不是如何做到这一点,但更仔细的检查,因为到如果这是避免对新的code ++模板缓存的实际方法是什么?我已经看到了角禁用模板缓存的例子,但现在看来似乎是我想在两者之间code文件时不改变推。使用

My question is not how to do this but more of a sanity check as to if this is a practical way of avoiding template caching on new code? I have seen examples of disabling template caching in angular but it seems like it is something I would want to use in between code pushes when files are not changing.

如何等浏览这个问题?

推荐答案

我觉得一个流行的做法是使用类似NG-模板(带的咕噜插件)生成一个JS文件pre-缓存所有的模板。然后使用 usemin 咕噜的工作流与资产版本的任务版本JS文件一起。

I think a popular approach is to use something like ng-templates (with a grunt plugin) to generate a JS file that pre-caches all of your templates. Then use the usemin grunt workflow along with an asset versioning task to version the JS file.

这篇关于这是模板缓存中的角破坏的好方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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