我知道捆绑和缩小仅在不处于调试模式时才有效。
<compilation debug="false" targetFramework="4.5"/>
如果我按 Ctrl + F5 来运行我的SPA,它可以正常工作。
但是,如果按 F5 启用调试,即使debug=false
上的web.config
,我的页面也无法正确加载。当我检查开发人员工具时,I found this。
如果我检查我的代码和我的脚本库,似乎没问题。
BundleConfig.cs :
public static void RegisterBundles(BundleCollection bundles)
{
bundles.IgnoreList.Clear();
AddDefaultIgnorePatterns(bundles.IgnoreList);
bundles.Add(
new ScriptBundle("~/scripts/modernizr")
.Include("~/scripts/modernizr-{version}.js"));
bundles.Add(
new ScriptBundle("~/scripts/vendor")
.Include("~/scripts/jquery-{version}.min.js")
.Include("~/scripts/bootstrap.min.js")
.Include("~/scripts/knockout-{version}.js")
.Include("~/scripts/toastr.js"));
bundles.Add(
new StyleBundle("~/Content/css")
.Include("~/Content/ie10mobile.css") // Must be first. IE10 mobile viewport fix
.Include("~/Content/bootstrap.min.css")
.Include("~/Content/bootstrap-responsive.min.css")
.Include("~/Content/font-awesome.min.css")
.Include("~/Content/toastr.css")
.Include("~/Content/styles.css")
);
}
VS工作室结构,files are there。
如果我查看我的index.cshtml
@using System.Web
@using System.Web.Optimization
<!DOCTYPE html>
<html>
<head>
<title>CCJS</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
@Styles.Render("~/Content/css")
<script language="javascript">
// Must be first. IE10 mobile viewport fix
if (navigator.userAgent.match(/IEMobile\/10\.0/)) {
var msViewportStyle = document.createElement("style");
var mq = "@@-ms-viewport{width:auto!important}";
msViewportStyle.appendChild(document.createTextNode(mq));
document.getElementsByTagName("head")[0].appendChild(msViewportStyle);
}
</script>
@Scripts.Render("~/scripts/modernizr")
</head>
<body>
<div id="applicationHost">
@RenderPage("_splash.cshtml")
</div>
@Scripts.Render("~/scripts/vendor")
<script src="~/Scripts/require.js" data-main="App/Main"></script>
</body>
</html>
答案 0 :(得分:1)
您可以将此行添加到BundleConfig.cs
//note: you can map isCompressionEnabled to your webconfig appSettings
BundleTable.EnableOptimizations = isCompressionEnabled;