如何在捆绑软件中对javascript文件进行版本控制?

编程入门 行业动态 更新时间:2024-10-11 23:21:04
本文介绍了如何在捆绑软件中对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) );请参阅此处的捆绑缓存: www.asp/ 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: www.asp/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文件进行版本控制?

本文发布于:2023-11-08 06:44:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568633.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中对   版本   文件   如何在   软件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!