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).
我正试图在我的角度应用程序上实现一些缓存清除,它仍然允许缓存,但只要我们将新代码推送到生产中就可以打破它。到目前为止,我的设置涉及使用grunt缓存破解程序https://www.npmjs.org/package/grunt-cache-breaker挖掘我的连接的角度app.js文件,并将查询参数追加到以.html文件结尾的任何字符串延期。我也为我使用ng-include的模板文件执行此操作。这样做的一个复杂因素是,现在我需要先将模板文件复制到dist /目录,这样我就可以安全地.gitignore缓存被破坏的版本,而不必每次缓存缓存时都提交我的所有模板(并产生冲突) 。
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.
我的问题不是如何做到这一点,而是更多的理智检查是否这是一种避免新代码模板缓存的实用方法?我已经看到了以角度方式禁用模板缓存的示例,但似乎在文件未更改时,我希望在代码推送之间使用它。
How do other navigate this issue?
其他人如何解决这个问题?
1 个解决方案
#1
9
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.
我认为一种流行的方法是使用ng-templates(带有一个grunt插件)来生成一个预先缓存所有模板的JS文件。然后使用usemin grunt工作流以及资产版本控制任务来对JS文件进行版本控制。
#1
9
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.
我认为一种流行的方法是使用ng-templates(带有一个grunt插件)来生成一个预先缓存所有模板的JS文件。然后使用usemin grunt工作流以及资产版本控制任务来对JS文件进行版本控制。