Javascript 捆绑和缩小混淆
我正在使用ASP.NET Web表单和母版页。有这么多的运动部件,我无法理解。不同的教程使用不同的部分,而忽略了其他部分,因此我无法确定需要什么和什么是无用的 不同部分: 母版页:在我的CSS的标题部分,我有:Javascript 捆绑和缩小混淆,javascript,c#,css,asp.net,bundling-and-minification,Javascript,C#,Css,Asp.net,Bundling And Minification,我正在使用ASP.NET Web表单和母版页。有这么多的运动部件,我无法理解。不同的教程使用不同的部分,而忽略了其他部分,因此我无法确定需要什么和什么是无用的 不同部分: 母版页:在我的CSS的标题部分,我有: <link href="Content/css" rel="stylesheet" /> <asp:PlaceHolder runat="server"> <%: Scripts.Render("~/bundles/modernizr")
<link href="Content/css" rel="stylesheet" />
<asp:PlaceHolder runat="server">
<%: Scripts.Render("~/bundles/modernizr") %>
</asp:PlaceHolder>
Web.config:
我添加了System.Web.Optimization命名空间和Microsoft.AspNet.Web.Optimization.WebForms程序集
Bundle.config:我不知道这是干什么用的;很多教程甚至没有提到它
BundleConfig.cs:除了标准的WebFormsJs、MsAjaxJs和Modernizer自定义捆绑包之外,我还有以下CSS:
bundles.Add(new StyleBundle("~/bundles/css").Include(
"~/Content*"));
这是行不通的。我正要为我的JS文件添加一些类似的东西,但我不明白为什么要这么做,而根据,CSS所需要的只是:
<link href="Content/css" rel="stylesheet" />
大概,我的JS文件只需要:
<script src="Scripts/js"></script>
在一些教程中,我看到了ScriptManager.ScriptResourceMapping.AddDefinition
-这是干什么用的
以下是我的CSS和脚本文件夹的当前状态-我需要这些文件夹的所有非迷你版本:
有人能帮我把这个拼起来吗?我正在本地运行,调试设置为false。下面是需要在WebForms中进行捆绑和缩小配置的每个部分的列表 这是从运行捆绑和缩小的生产代码库中获取的 库:
<!-- 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>
- Microsoft.AspNet.Web.Optimization
<!-- 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>
- 网脂
- Microsoft.Web.Infrastructure(取决于版本)
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类
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>
非常感谢你的回答。我在这里得到了关于Bundle.config文件用途的更多细节:一个附带的问题:如果一切正常,并且按照您的解释,它确实正常。。。我真的需要这个吗@IrishChieftain我不熟悉这个标签,但你可能会删除它,因为你已经涵盖了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>