捆绑和缩小混淆
Bundling and Minification Confusion
我正在使用带有母版页的 ASP.NET Web 表单。这有太多的活动部分,我无法弄清楚。不同的教程使用它的不同部分并省略其他部分,我无法确定需要什么,什么是绒毛。
不同部位:
Master Pages:在我的 CSS 的头部部分,我有:
<link href="Content/css" rel="stylesheet" />
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
在关闭 body 标签之前,我有:
<script src="<%= ResolveUrl("~") %>Scripts/jquery-2.1.1.js"></script>
<script src="<%= ResolveUrl("~") %>Scripts/bootstrap.min.js"></script>
<script src="<%= ResolveUrl("~") %>Scripts/jquery.reject.js"></script>
<script src="<%= ResolveUrl("~") %>Scripts/general.js"></script>
看起来不需要最小的,但我需要其中的任何一个,而是使用
<script src="Scripts/js"></script> ?
Global.asax.cs:这看起来很简单,在 Application_Start 方法中注册包。
void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Web.config:
我添加了 System.Web.Optimization 命名空间和 Microsoft.AspNet.Web.Optimization.WebForms 程序集。
Bundle.config:我不知道这是干嘛的;许多教程甚至都没有提到它?
BundleConfig.cs:除了标准的 WebFormsJs、MsAjaxJs 和 modernizr 自定义包外,我还有以下 CSS:
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/Content*"));
这是行不通的。我正要为我的 JS 文件添加类似的东西,但是根据 this tutorial,我对为什么要这样做感到困惑,我需要的 CSS 是:
<link href="Content/css" rel="stylesheet" />
据推测,我的 JS 文件所需的全部是:
<script src="Scripts/js"></script>
在我看到的一些教程中 ScriptManager.ScriptResourceMapping.AddDefinition
- 这是做什么用的?
这是我的 CSS 和脚本文件夹的当前状态 - 我需要这些文件夹的所有非压缩版本:
有人可以帮我拼凑一下吗?我在本地 运行,调试设置为 false。
下面列出了需要为 WebForms 中的捆绑和缩小配置的每个部分。
这取自运行 捆绑和缩小的生产代码库。
图书馆:
- Microsoft.AspNet.Web.Optimization
依赖关系:
- WebGrease
- Microsoft.Web.Infrastructure(取决于版本)
Global.asax
void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
//Use this if you want to force/test bundling in debug.
BundleTable.EnableOptimizations = true;
}
BundleConfig class
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/sitejs")
//Add as many JS libraries you would like to the bundle...
.Include("~/Scripts/jquery-3.1.1.js")
.Include("~/Scripts/jquery-migrate-3.0.0.js")
);
bundles.Add(new StyleBundle("~/bundles/sitecss")
//Add as many CSS files that you would like to the bundle...
.Include("~/css/jquery-ui.css")
);
}
}
母版页:
<!-- At the top of the Master Page -->
<%@ Import Namespace="System.Web.Optimization" %>
<!-- Just after the closing `</form>` tag -->
<asp:PlaceHolder runat="server">
<%: Styles.Render("~/bundles/sitecss") %
<%: Scripts.Render("~/bundles/sitejs") %
</asp:PlaceHolder>
我正在使用带有母版页的 ASP.NET Web 表单。这有太多的活动部分,我无法弄清楚。不同的教程使用它的不同部分并省略其他部分,我无法确定需要什么,什么是绒毛。
不同部位:
Master Pages:在我的 CSS 的头部部分,我有:
<link href="Content/css" rel="stylesheet" />
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
在关闭 body 标签之前,我有:
<script src="<%= ResolveUrl("~") %>Scripts/jquery-2.1.1.js"></script>
<script src="<%= ResolveUrl("~") %>Scripts/bootstrap.min.js"></script>
<script src="<%= ResolveUrl("~") %>Scripts/jquery.reject.js"></script>
<script src="<%= ResolveUrl("~") %>Scripts/general.js"></script>
看起来不需要最小的,但我需要其中的任何一个,而是使用
<script src="Scripts/js"></script> ?
Global.asax.cs:这看起来很简单,在 Application_Start 方法中注册包。
void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
Web.config:
我添加了 System.Web.Optimization 命名空间和 Microsoft.AspNet.Web.Optimization.WebForms 程序集。
Bundle.config:我不知道这是干嘛的;许多教程甚至都没有提到它?
BundleConfig.cs:除了标准的 WebFormsJs、MsAjaxJs 和 modernizr 自定义包外,我还有以下 CSS:
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/Content*"));
这是行不通的。我正要为我的 JS 文件添加类似的东西,但是根据 this tutorial,我对为什么要这样做感到困惑,我需要的 CSS 是:
<link href="Content/css" rel="stylesheet" />
据推测,我的 JS 文件所需的全部是:
<script src="Scripts/js"></script>
在我看到的一些教程中 ScriptManager.ScriptResourceMapping.AddDefinition
- 这是做什么用的?
这是我的 CSS 和脚本文件夹的当前状态 - 我需要这些文件夹的所有非压缩版本:
有人可以帮我拼凑一下吗?我在本地 运行,调试设置为 false。
下面列出了需要为 WebForms 中的捆绑和缩小配置的每个部分。
这取自运行 捆绑和缩小的生产代码库。
图书馆:
- Microsoft.AspNet.Web.Optimization
依赖关系:
- WebGrease
- Microsoft.Web.Infrastructure(取决于版本)
Global.asax
void Application_Start(object sender, EventArgs e)
{
BundleConfig.RegisterBundles(BundleTable.Bundles);
//Use this if you want to force/test bundling in debug.
BundleTable.EnableOptimizations = true;
}
BundleConfig class
public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/sitejs")
//Add as many JS libraries you would like to the bundle...
.Include("~/Scripts/jquery-3.1.1.js")
.Include("~/Scripts/jquery-migrate-3.0.0.js")
);
bundles.Add(new StyleBundle("~/bundles/sitecss")
//Add as many CSS files that you would like to the bundle...
.Include("~/css/jquery-ui.css")
);
}
}
母版页:
<!-- At the top of the Master Page -->
<%@ Import Namespace="System.Web.Optimization" %>
<!-- Just after the closing `</form>` tag -->
<asp:PlaceHolder runat="server">
<%: Styles.Render("~/bundles/sitecss") %
<%: Scripts.Render("~/bundles/sitejs") %
</asp:PlaceHolder>