如何捆绑外部脚本&字体是否合适?

时间:2016-04-21 09:46:52

标签: asp.net-mvc

我试图捆绑1个外部脚本& 2个外部谷歌字体,但正确捆绑它们有问题。

这些是我试图捆绑的内容:

<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Merriweather:400,300,700,900' rel='stylesheet' type='text/css' />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>

在我的BundleConfig中,我启用了usecdn并创建了3个cdnPath&#39; s,如下所示:

bundles.UseCdn = true;

var cdnPath1 = "~/http://maps.google.com/maps/api/js?sensor=false";
var cdnPath2 = "~/http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic";
var cdnPath3 = "~/http://fonts.googleapis.com/css?family=Merriweather:400,300,700,900";

bundles.Add(new ScriptBundle("~/bundles/topjs").Include(
                                    cdnPath1));

bundles.Add(new ScriptBundle("~/Content/fonts").Include(
                                    cdnPath2,
                                    cdnPath3));

我在_Layout.cshtml中渲染了它们:

@Styles.Render("~/Content/css")
@Styles.Render("~/bundles/fonts")

问题是外部javascript文件和2个谷歌字体无效并且没有显示。

1 个答案:

答案 0 :(得分:3)

您无法捆绑多个cdns。只有本地文件可以捆绑在一起 检查以下链接: http://venkatbaggu.com/use-cdn-bundle-config-in-asp-net-mvc/ http://www.asp.net/mvc/overview/performance/bundling-and-minification(选中使用CDN标题)