星期三, 8月 20, 2008

Using the scriptmanager control to combine javascript

最近更新完vs2008的sp1..上官方網站看..看到有一個不錯玩的東西..就是script manager可以把網頁的所有javascript合併起來..變成一個整理(壓縮?..檔案有變小)好的javascript..這點真的蠻吸引人的..因為ajax的引入還有jquery的使用..網頁裡一堆javascript..看起來fu就不太對..Hot..

首先我們先去載一個ScriptReferenceProfiler來幫助你把頁面上所有的javascript抓出來..

使用前:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Scripts>
<asp:ScriptReference Path="~/js/jquery-1.2.6.js" />
</Scripts>
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc2:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="TextBox1">
</cc2:SliderExtender>
<cc1:ScriptReferenceProfiler ID="ScriptReferenceProfiler1" runat="server" />
</div>
</form>

dfd

使用後:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<CompositeScript>
<Scripts>
<asp:ScriptReference Name="MicrosoftAjax.js" />
<asp:ScriptReference Name="MicrosoftAjaxWebForms.js" />
<asp:ScriptReference Path="~/js/jquery-1.2.6.js" />
<asp:ScriptReference Name="AjaxControlToolkit.Compat.Timer.Timer.js"
Assembly="AjaxControlToolkit, Version=3.0.20229.20843, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" />
<asp:ScriptReference Name="AjaxControlToolkit.Common.Common.js"
Assembly="AjaxControlToolkit, Version=3.0.20229.20843, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" />
<asp:ScriptReference Name="AjaxControlToolkit.Animation.Animations.js"
Assembly="AjaxControlToolkit, Version=3.0.20229.20843, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" />
<asp:ScriptReference Name="AjaxControlToolkit.Compat.DragDrop.DragDropScripts.js"
Assembly="AjaxControlToolkit, Version=3.0.20229.20843, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" />
<asp:ScriptReference Name="AjaxControlToolkit.ExtenderBase.BaseScripts.js"
Assembly="AjaxControlToolkit, Version=3.0.20229.20843, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" />
<asp:ScriptReference Name="AjaxControlToolkit.Slider.SliderBehavior.js"
Assembly="AjaxControlToolkit, Version=3.0.20229.20843, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e" />
</Scripts>
</CompositeScript>
</asp:ScriptManager>
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<cc2:SliderExtender ID="SliderExtender1" runat="server" TargetControlID="TextBox1">
</cc2:SliderExtender>
<cc1:ScriptReferenceProfiler ID="ScriptReferenceProfiler1" runat="server" />
</div>
</form>

ghy

很簡單就把javascript整理起來了..感覺還真不錯..推薦啦..還有記得要vs2008 sp1才行ㄟ..KissKissKissKiss..

ps:這裡有影片..看這比較快..

參考:

沒有留言: