如何在捆绑软件中对javascript文件进行版本控制? [英] How to version javascript files in a Bundle?

查看:50
本文介绍了如何在捆绑软件中对javascript文件进行版本控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将我的JS脚本包含在捆绑包中,并同时版本,以避免在脚本被更改时避免浏览器缓存。

I want to include my JS scripts in a Bundle AND at the same time version them to avoid browser caching if those scripts have been changed.

使用 ASP.NET MVC 5 是否有 native 方式来实现这一目标?

Is there a "native" way with ASP.NET MVC 5 to accomplish this?

我找到了一个名为盒式磁带的库,它可以完成此操作(自动对JS进行版本控制一件好事),但我想简化一些事情(甚至),而无需太多更改我的脚本配置...

I've found a library called Cassette that does exactly this (automatically versioning the JS, which is a good thing) but I wanted something (even) simpler, without changing a lot my script configuration...

以下操作无效:

 var version = ConfigurationManager.AppSettings["cache"].ToString();
 bundles.Add(new ScriptBundle("~/bundles/scripts").Include(
     "~/Scripts/framework.js" + version,
     "~/Scripts/main.js"));

结果是浏览器未下载 framework.js文件(可能不是

The result is that the "framework.js" file is not downloaded by the browser (probably is not found).

推荐答案

MVC将自动为发布版本添加版本参数(即,如果web.config中的debug = false) );请参阅此处的捆绑缓存: http://www.asp.net/ mvc / overview / performance / bundle-and-minification

MVC will automatically add a version parameter for release builds (i.e. if debug="false" in web.config); see "Bundle Caching" here: http://www.asp.net/mvc/overview/performance/bundling-and-minification

您可以在调试版本中明确启用此功能(在同一篇文章中介绍),但是您的脚本会被缩小为同一动作的一部分;没有单独的方法。

You can explicitly enable this in debug builds (described in the same article), but your scripts will be minified as part of the same action; there's no separate method to do so.

这篇关于如何在捆绑软件中对javascript文件进行版本控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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