推出新版本的JavaScript,css&图形内容,使用ASP .NET MVC [英] Push out a new version of JavaScript, css & graphic content, using ASP .NET MVC

查看:43
本文介绍了推出新版本的JavaScript,css&图形内容,使用ASP .NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望通过< script>引用的JavaScript标签,我的CSS和要在我的网站的给定版本中缓存在用户浏览器中的各种图形文件。但是,当我发布文件更新时,我想确保新内容(Javascript,CSS,图形等)将在用户的计算机上更新。

I want my JavaScript that's referenced through <script> tags, my css, and various graphic files to be cached on the user browser for a given release of my site. However, when I release an update to a file, I would like to ensure that the new content (Javascript, css, graphics, etc) will be updated on the user's machine.

在研究此问题时,我遇到了许多可能的解决方案:

In researching this problem, I've come across a number of possible solutions:


  1. 针对缓存控制之类的内容调整http标头并使其过期

  2. 向每个资源请求附加唯一的查询字符串

  3. 在所请求资源的路径(或文件名)中包含版本号

我对选项1的关注(除了不知道如何为某些内容类型实现之外)是,如果浏览器和IIS之间存在中间代理, ,那么中间代理可能不会遵守http标头,并且内容将被缓存在浏览器和代理之间。

My concern with option 1 (other than not knowing how to implement it for some content types) is that if there's an intermediate proxy between the browser and IIS, then the intermediate proxy may not respect the http headers, and the content would be cached between the browser and the proxy.

我对选项2的关注有两个方面。例如,如果我只是使用随机数或时间戳,那么浏览器每次都会请求一个新资源,即使内容没有更改(两次发布之间没有更改),也会绕过本地缓存。解决此问题的方法是使用资源文件的时间戳或文件的哈希。仅当出现新版本时,这种情况才会改变。但是,这引起了我的第二个担忧:我了解到,默认情况下,某些Web代理从不缓存任何带有查询字符串的内容(http://stackoverflow.com/questions/5541340/how-can-i-prevent-javascript-caching- querystring-approach-isnt-working)。虽然这可能是可定制的,但我不想依靠管理员更改默认设置来获得缓存的性能优势。

My concern with option 2 is two fold. For one, if I just use a random number or timestamp, then the browser will request a new resource every time, bypassing the local cache even when the content hasn't changed (when not between releases). A workaround to this problem is to use the timestamp of the resource file or a hash of the file; this would change only when a new release occurs. However, this lead to my second concern: I understand that some web proxies never cache anything with a query string, by default (http://stackoverflow.com/questions/5541340/how-can-i-prevent-javascript-caching-querystring-approach-isnt-working). While this is likely customizable, I wouldn't want to rely on the administrator changing a setting from the default, in order to get the performance benefit of caching.

选项3似乎是最好的选择,但是对于ASP .NET MVC(当前使用ASP .NET MVC 3),我不知道如何以实用的方式实现它。用手,我可以进入链接到图形,css或外部javascript文件的每个文件,并更改路径以为每个发行版包含不同的版本号,但这显然很繁琐且容易出错。

Option 3 seems like the best choice, but I don't know how to implement it in a practical manner, for ASP .NET MVC (currently using ASP .NET MVC 3). By hand, I could go into every file that links to a graphic, css or external javascript file and change the path to include a different version number for each release, but clearly this is tedious and error prone.

我的问题是:

1)是否有其他避免缓存的策略(对于给定的发行版) ),我应该考虑并

1) Are there any other strategies to avoid caching (for a given release) that I should consider and

2),假设我使用选项3(包括资源路径中的版本号),如何在ASP中实现此目标.NET MVC应用程序,以一种切实可行的方式进行维护?

2) assuming I use option 3 (including a version number in the path of the resource), how I can I achieve this in an ASP .NET MVC application, in a way that is realistic to maintain?

谢谢

Notre

推荐答案

这个想法是,只要js,css文件的版本更改,您就必须更改服务器的URL,因此浏览器要求新版本。

The idea is whenever the version of the js, css files changes you have to change the URL from the server so the browser request for the new version.

请在此线程。虽然答案是在php中,但是它可以在asp.net mvc本身中实现。

Please refer the answer of @Kip in this thread that clearly describes about this. Though the answer is in php it can be implemented in asp.net mvc itself.

如果您使用的是ASP.NET MVC 4的新捆绑/最小化功能,我认为版本管理将由它自动进行(不确定)。

If you are using the new bundling/minification feature of ASP.NET MVC 4 I think the versioning be taken care automatically by it(not sure though).

这篇关于推出新版本的JavaScript,css&amp;图形内容,使用ASP .NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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