ASP.NET MVC5捆绑包如果Google jqueryUI无法使用捆绑包,如何返回到我的托管库?
我正在创建一个asp.net mvc应用程序。我已经为我的脚本和样式表创建了捆绑包,并且为每个捆绑包使用了google cdn。 我有两个问题: 1.如果谷歌的jquery和jqueryUI cdn失败,我应该如何以及在哪里创建一个后备方案? 2.我是否必须为每个bundle(也就是样式bundle)创建回退 这是我的bundleConfig.cs:ASP.NET MVC5捆绑包如果Google jqueryUI无法使用捆绑包,如何返回到我的托管库?,jquery,asp.net-mvc,Jquery,Asp.net Mvc,我正在创建一个asp.net mvc应用程序。我已经为我的脚本和样式表创建了捆绑包,并且为每个捆绑包使用了google cdn。 我有两个问题: 1.如果谷歌的jquery和jqueryUI cdn失败,我应该如何以及在哪里创建一个后备方案? 2.我是否必须为每个bundle(也就是样式bundle)创建回退 这是我的bundleConfig.cs: bundles.Add(new ScriptBundle("~/bundles/jqueryui", "https://ajax.googleap
bundles.Add(new ScriptBundle("~/bundles/jqueryui", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery", "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval", "https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.17.0/jquery.validate.min.js").Include(
"~/Scripts/jquery.validate*"));
// Use the development version of Modernizr to develop with and learn from. Then, when you're
// ready for production, use the build tool at https://modernizr.com to pick only the tests you need.
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new ScriptBundle("~/bundles/bootstrap", "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js").Include(
"~/Scripts/bootstrap.js"));
bundles.Add(new StyleBundle("~/Content/css", "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css").Include(
"~/Content/bootstrap.css",
"~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css", "https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/themes/smoothness/jquery-ui.css").Include(
"~/Content/themes/base/core.css",
"~/Content/themes/base/resizable.css",
"~/Content/themes/base/selectable.css",
"~/Content/themes/base/accordion.css",
"~/Content/themes/base/autocomplete.css",
"~/Content/themes/base/button.css",
"~/Content/themes/base/dialog.css",
"~/Content/themes/base/slider.css",
"~/Content/themes/base/tabs.css",
"~/Content/themes/base/datepicker.css",
"~/Content/themes/base/progressbar.css",
"~/Content/themes/base/theme.css"));
BundleTable.EnableOptimizations = true;
bundles.UseCdn = true;
}
这是我的layout.cshtml
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/modernizr")
@ViewBag.Title-我的ASP.NET应用程序
@style.Render(“~/Content/css”)
@style.Render(“~/Content/themes/base/css”)
@Scripts.Render(“~/bundles/modernizer”)
@RenderBody()
&抄袭@DateTime.Now.Year-我的ASP.NET应用程序
@Scripts.Render(“~/bundles/jquery”)
@Scripts.Render(“~/bundles/jqueryui”)
@Scripts.Render(“~/bundles/bootstrap”)
@RenderSection(“脚本”,必需:false)
在我看来,将CDN捆绑在一起没有多大意义。只需确保您使用的是缩小版 有关添加回退的信息,请参见下面的示例: 将引导CSS和Modernizer放在HTML的
中:
<html>
<head>
/* Referencing bootstrap CSS from CDN */
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
/* Referencing Modernizr from CDN */
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js"></script>
更新 如果您想将CDN放在一个捆绑包中(不确定为什么?) //在CDN上添加jquery的链接
var jqueryCdnPath = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
以下是将其添加到页面的方式:
@Scripts.Render(“~/bundles/jquery”)
if(typeof jQuery==“未定义”){
var e=document.createElement('script');
e、 src='@Url.Content(“~/Scripts/jquery-1.7.1.js”);
e、 类型='text/javascript';
document.getElementsByTagName(“head”)[0].appendChild(e);
}
在我看来,将CDN捆绑在一起没有多大意义。只需确保您使用的是缩小版 有关添加回退的信息,请参见下面的示例: 将引导CSS和Modernizer放在HTML的
中:
<html>
<head>
/* Referencing bootstrap CSS from CDN */
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
/* Referencing Modernizr from CDN */
<script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.8.3/modernizr.js"></script>
更新 如果您想将CDN放在一个捆绑包中(不确定为什么?) //在CDN上添加jquery的链接
var jqueryCdnPath = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
以下是将其添加到页面的方式:
@Scripts.Render(“~/bundles/jquery”)
if(typeof jQuery==“未定义”){
var e=document.createElement('script');
e、 src='@Url.Content(“~/Scripts/jquery-1.7.1.js”);
e、 类型='text/javascript';
document.getElementsByTagName(“head”)[0].appendChild(e);
}
非常感谢。只是想知道cdn是如何作为后备包链接到每个捆绑包的,是document.write只链接到一个脚本?我的问题是如何使用捆绑包和cdn?如何在发布我的应用程序时为cdn创建后备包?@JaneCohen:我已经更新了我的答案,说明了如何在捆绑包中使用cdn我理解你关于不使用捆绑包的观点。。只是想知道我会在样式包(有多个样式表)的布局中做什么,如果我不使用绑定,我将如何为每个样式附加cdn回退方法谢谢!只是想知道cdn是如何作为后备包链接到每个捆绑包的,是document.write只链接到一个脚本?我的问题是如何使用捆绑包和cdn?如何在发布我的应用程序时为cdn创建后备包?@JaneCohen:我已经更新了我的答案,说明了如何在捆绑包中使用cdn我理解你关于不使用捆绑包的观点。。只是想知道我会在样式包(有多个样式表)的布局中做什么,如果我不使用绑定,我将如何为每个样式附加cdn回退方法
var jqueryCdnPath = "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.1.min.js";
bundles.Add(new ScriptBundle("~/bundles/jquery",
jqueryCdnPath).Include(
"~/Scripts/jquery-{version}.js"));
@Scripts.Render("~/bundles/jquery")
<script type="text/javascript">
if (typeof jQuery == 'undefined') {
var e = document.createElement('script');
e.src = '@Url.Content("~/Scripts/jquery-1.7.1.js")';
e.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(e);
}
</script>