admin管理员组文章数量:1418700
I am using the ASP.NET Bundling mechanism:
BundleTable.Bundles.Add(new ScriptBundle("~/Scripts/Master-js").Include(
"~/Scripts/respond.min.js",
"~/Scripts/jquery.form.js",
"~/Scripts/jquery.MetaData.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/bootstrap.js",
"~/Scripts/jquery.viewport.js",
"~/Scripts/jquery.cookie.js"
));
I want this to happen if the build is in release. If the build is in debug, I want the un-minified individual files to load so debugging would be easy.
The only way I have been able to do this is to write the following in my view:
<% if(HttpContext.Current.IsDebuggingEnabled)
{
Response.Write("<script type='text/javascript' src='../../Scripts/respond.min.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.form.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.MetaData.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.validate.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/bootstrap.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.viewport.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.cookie.js'></script>");
}
else
{
Scripts.Render("~/Scripts/Master-js");
}
%>
As you can see, I am repeating myself here. Is there a better way?
I am using the ASP.NET Bundling mechanism:
BundleTable.Bundles.Add(new ScriptBundle("~/Scripts/Master-js").Include(
"~/Scripts/respond.min.js",
"~/Scripts/jquery.form.js",
"~/Scripts/jquery.MetaData.js",
"~/Scripts/jquery.validate.js",
"~/Scripts/bootstrap.js",
"~/Scripts/jquery.viewport.js",
"~/Scripts/jquery.cookie.js"
));
I want this to happen if the build is in release. If the build is in debug, I want the un-minified individual files to load so debugging would be easy.
The only way I have been able to do this is to write the following in my view:
<% if(HttpContext.Current.IsDebuggingEnabled)
{
Response.Write("<script type='text/javascript' src='../../Scripts/respond.min.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.form.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.MetaData.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.validate.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/bootstrap.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.viewport.js'></script>");
Response.Write("<script type='text/javascript' src='../../Scripts/jquery.cookie.js'></script>");
}
else
{
Scripts.Render("~/Scripts/Master-js");
}
%>
As you can see, I am repeating myself here. Is there a better way?
Share Improve this question asked Nov 4, 2013 at 18:41 BarkaBarka 8,94216 gold badges69 silver badges94 bronze badges 2-
4
If you run the site in debug mode and use
Scripts.Render("~/Scripts/Master-js");
on your view, it should have the non-minified version served with separate script tags for each. – Steven V Commented Nov 4, 2013 at 18:44 - @StevenV, if you add your ment as a anser, I will mark it as correct. Many thanks for your help. – Barka Commented Nov 11, 2013 at 23:48
1 Answer
Reset to default 7By default, when using Scripts.Render()
on your view and if the application has debugging enabled (debug="true"
in the web.config) the files will not be bundled or minified. Also a individual script tag will be rendered for every asset in that bundle.
You can manually enable/disable bundling and minification by using System.Web.Optimization.BundleTable.EnableOptimizations
本文标签: cBundling and not bundling in production and test environments in ASPNET MVCStack Overflow
版权声明:本文标题:c# - Bundling and not bundling in production and test environments in ASP.NET MVC - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745295335a2652041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论