asp.net scriptbundle多个include vs single include

Hel*_*rld 5 asp.net bundling-and-minification scriptbundle

捆绑有什么区别:

  bundles.Add(new ScriptBundle("~/bundles/jquery")
  .Include("~/Scripts/jquery-{version}.js","file2.js", "file3.js"));
Run Code Online (Sandbox Code Playgroud)

VS

   bundles.Add(new ScriptBundle("~/bundles/jquery")
                .Include("~/Scripts/jquery-{version}.js")
                .Include("file2.js")
                .Include("file3.js"));
Run Code Online (Sandbox Code Playgroud)

我可以在ONE include方法中放入许多脚本,或者我可以使用许多include方法.

我什么时候应该用什么?

Bri*_*den 4

任何一个选择都可以,这是一个语法、可读性的选择。Include("resource1", "resource2", "resourceN")是使用关键字的 Include 方法的简单重载params。在 C# 中,params关键字允许使用可变数量的参数。

Include('Resource1").Include("Resource2").Include("ResourceN")是 Include 方法的一种不同签名,它接受一个字符串参数。Include("resource1").include("resource2") 是简单的链接。

这两种语法最终都会调用相同的代码来添加“资源”字符串路径。您只需调用 Include 方法的不同签名/重载定义来传递字符串资源/js 参数。