2011-12-09 36 views
-1

在asp:ScriptManager中,我像這樣加載jQuery。如何在ScriptManager中添加Jquery cdn,如果加載失敗,然後從本地文件加載

<asp:ScriptManager ID="ScriptManagerMasterPage" runat="server"> 
    <Scripts> 
     <asp:ScriptReference Path="~/Scripts/jquery-1.6.4.min.js" /> 
     <asp:ScriptReference Path="~/Scripts/jquery-ui-1.8.16.min.js" /> 
     <asp:ScriptReference Path="~/Scripts/tag-it.js" /> 
     <asp:ScriptReference Path="~/Scripts/MosJScript.js" /> 
     <asp:ScriptReference Path="~/Scripts/jquery.tools.min.js" /> 
     <asp:ScriptReference Path="~/Scripts/jquery.dragsort.js" /> 
     <asp:ScriptReference Path="~/Scripts/jquery.ad-gallery.pack.js" /> 
    </Scripts> 
</asp:ScriptManager> 

假設我想從谷歌使用jquery cdn,但如果cdn文件未能加載,那麼我會從本地機器加載。這個怎麼做。

+1

我真想問你是否要通過代碼在你的HTML做到這一點...頁面的加載時間時,CDN也失敗可能是太可怕了 - 試想如果CDN是緩慢的,需要一個很長一段時間超時,它會阻止該頁面,直到每個元素超時爲止...如果您不能相信CDN使用不同的CDN,即您可以信任的CDN。 –

回答

1

我認爲您正在尋找類似於this的東西。搜索詞是'fall-back'文件。

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.3.2.min.js"></script> 
<script type="text/javascript"> 
if (typeof jQuery == 'undefined') 
{ 
    document.write(unescape("%3Cscript src='/Scripts/jquery-1.3.2.min.js' type='text/javascript'%3E%3C/script%3E")); 
} 
</script> 
+0

感謝看來我們不能在ScriptManager中使用它,對吧? –

+1

您可以隨時將該腳本塊放入腳本文件中並將其包含在ScriptManager中。注意:我不知道ScriptManager的執行順序是否遵守順序。 – rkw

相關問題