问题描述
更改我们的大多数资源时,客户端都会遇到缓存问题,因为客户端的缓存不会在每个版本中都失效.
The clients have a caching problem with most of our resources when we change them because the client's cache is not invalidated at every release.
可能的解决方案1:来自.net MVC,我正在考虑创建一个处理所有资源并为其分配版本的助手,例如:
Possible solution 1:Being from .net MVC, I was thinking about making an helper that handle every resources and assign them a version, example:
@SomeHelper.VersionJsFile("~/scripts/somejs1","~/scripts/somejs2","~/scripts/somejs3")
将输出:
<script src="~/scripts/somejs1?v=1234">
<script src="~/scripts/somejs2?v=1234">
...
问题:我不知道如何在ASP .net中进行类似的操作.问题2:很多文件,可能会忘记其中一些.
The problem: I dont know how to do such similar thing in ASP .net.The problem2: Lots of file and may forget some of them.
可能的解决方案2:另一种解决方案是遍历所有文件(很多文件……实际上是一堆文件)并手动输入版本:
Possible solution 2:The other solution would be to go trough all the files (a lot of files... Actually, a sh*tload of files) and enter the version manually:
<script src="scripts/somejs1.js?v=<%=version %>
问题:文件很多,可能会忘记其中的一些.
The problem: Lots of file and may forget some of them.
可能的解决方案3:如以下示例所述,编写自定义过滤器流:过滤器流示例
Possible solution 3:Writing a custom filter stream as described in this example: Filter stream example
问题:危险,如果过滤器崩溃,客户端可能根本无法使用该软件.问题2:由于我不习惯使用流,因此很难正确实施.问题3:对于将来的开发者而言,维护工作相当困难".
The problem: Dangerous, if the filter crashes, the client may not be able to use the software at all.The problem2: Quite "hard" to properly implement since I'm not used to work with streams.The problem3: Quite "hard" to maintain for future devs.
可能的解决方案4:使用YUI压缩工具.不用考虑这是遗留代码,为时已晚.
Possible solution 4:Use YUIcompression tool. Don't think about it. This is legacy code and it is too late for that.
我的问题:在这种系统中版本文件的最佳方法是什么?如果我已经找到了好的解决方案,那么您是否有正确实施上述解决方案的提示?
My question: What is the best way to version file in such system? If I already found the good solution, do you have tips on how to properly implement the said solution?
推荐答案
使用盒式磁带用于js资源的捆绑和版本控制.它支持网络表单,仅在选项中用于版本控制/缓存清除.在配置中将需要一些资源的设置,但是您只需要一次配置它,页面便可以在需要时引用它们的资源.
I've had a lot of luck using Cassette for both bundling and versioning of js resources. It supports webforms, and be used for versioning/cache busting only in the options. It would take a bit of setup of your resources in the configuration, but you would only need to configure it in once place and the pages can just reference their resources when they need it.
这篇关于在一个庞大的asp.net旧版项目中,对javascript文件进行版本控制的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!