2017-07-28 37 views
-1

我正在嘗試利用Azure CDN儘快加載我的包。使用CDN在單個包中添加多個腳本/樣式

我想在每個包和網絡選項卡中添加多個不同的文件我可以看到它只加載'cdnAddress'而不是其中的獨特文件,因此每個包只會加載包含在'cdnAddress'。

bundles.Add(new StyleBundle("~/Resources/CSS/Plugins/Effects", cdnAddress).Include("~/Content/Styles/Animate/animate.min.css").Include("~/Content/Styles/Hover/hover-min.css")); 

上面的例子表明,我試圖把兩種不同的CSS文件放到同捆所以我只能就同時使用捆綁頁1個請求。但是CDN路徑只能提交一次。

我想將'cdnAddress'設置爲我的CDN的根網址,這可能嗎?如果不是,我怎樣才能實現我的目標,而不是兩個不同的捆綁。

由於我有很多捆綁包,我正在尋找一個易於維護的解決方案,我可以告訴它我的CDN在哪裏,並讓它找出文件的CDN路徑,因爲它們是我網站的鏡像。由於我在使用CMS,所以也可能不配置CDN,因此CDN路徑將爲空。

enter image description here

回答

1

我想成立 'cdnAddress' 是我的CDN的根URL,這可能嗎?如果不是,我怎樣才能實現我的目標,而不是兩個不同的捆綁。

AFAIK,你不能在一個包中提供多個CDN路徑。而ScriptBundle.Include可能包含多個本地虛擬路徑。

你可以按照下面的方法來達到你的目的:

  • 定義每個CDN路徑的束;

  • 您可以手動合併所有相關文件,並將它們上傳到您的cdn路徑,並使用此cdn路徑和多個本地虛擬路徑。

樣品:

bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
      "~/Scripts/bootstrap.js", 
      "~/Scripts/respond.js")); 
//TO 

bundles.UseCdn = true; 
bundles.Add(new ScriptBundle("~/bundles/bootstrap", "http://yourCdnSite/Scripts/bootstrap.js").Include(
      "~/Scripts/bootstrap.js")); 

bundles.Add(new ScriptBundle("~/bundles/bootstrap", "http://yourCdnSite/Scripts/respond.js").Include(
      "~/Scripts/respond.js")); 
BundleTable.EnableOptimizations = true; 

//OR 

bundles.UseCdn = true; 
bundles.Add(new ScriptBundle("~/bundles/bootstrap", "http://yourCdnSite/Scripts/<the-combination-of-bootstrap.js-and-respond.js>.js").Include(
      "~/Scripts/bootstrap.js", 
      "~/Scripts/respond.js")); 
BundleTable.EnableOptimizations = true; 
相關問題