问题描述
我创建了一个新项目.我从 NuGet 安装了 Ajax Control Toolkit.然后我使用以下代码创建了一个新页面 aspx:
当我看到ajaxtokit创建了152个脚本资源文件时,我傻眼了.我很担心,因为我知道这会影响页面的加载时间.
正常吗?
我能做什么?
CodePlex 于 2013 年 7 月发布的 AjaxControlToolkit 介绍控制包.
此后默认情况下 AjaxControlToolkit 加载所有脚本.因此,要管理应该添加和分组哪些控件的脚本,您需要将 AjaxControlToolkit.config 添加到您的 Web 应用程序项目的根目录.就像下面的例子:
<控制包><控制包><控件名称="CalendarExtender"/><控件名称="ComboBox"/></controlBundle><controlBundle 名称="CalendarBundle"><控件名称="CalendarExtender"></control></controlBundle></controlBundles></ajaxControlToolkit>
然后您需要通过将具有特定名称的包添加到工具包脚本管理器控件来指定将在哪个页面上使用哪些包(或母版页,如果您有在所有页面上使用的控件):
<ajaxToolkit:ToolkitScriptManager runat="server" CombineScripts="true"ScriptMode="发布" ><控制包><ajaxToolkit:ControlBundle Name="日历"/></ControlBundles></ajaxToolkit:ToolkitScriptManager>
备注:此处您可以找到配置示例其中包含最多(可能是ajax控件工具包库中控件的所有定义).
I created a new project. I installed Ajax Control Toolkit from NuGet. Then I created a new page aspx with following code:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ajaxToolkit:ToolkitScriptManager ID="toolkitScriptMaster" runat="server">
</ajaxToolkit:ToolkitScriptManager>
hello!!!!
</div>
</form>
</body>
</html>
I was dumbfounded when I saw that ajaxtookit created 152 scriptresources files.I am worried because I know that this can affect the loading time of the page.
Is it normal?
What can I do?
CodePlex's AjaxControlToolkit release of July 2013 introducing control bundles.
After this by default AjaxControlToolkit loads all scripts. So, to manage what scripts for what controls should be added and grouped you need to add AjaxControlToolkit.config to root of your web application project. Like in the following example:
<ajaxControlToolkit>
<controlBundles>
<controlBundle>
<control name="CalendarExtender" />
<control name="ComboBox" />
</controlBundle>
<controlBundle name="CalendarBundle">
<control name="CalendarExtender"></control>
</controlBundle>
</controlBundles>
</ajaxControlToolkit>
Then you will need to specify which bundels are going to be used on which page (or master page if you have controls which are used on all pages) by adding bundle with specific name to toolkit script manager control:
<ajaxToolkit:ToolkitScriptManager runat="server" CombineScripts="true"
ScriptMode="Release" >
<ControlBundles>
<ajaxToolkit:ControlBundle Name="Calendar" />
</ControlBundles>
</ajaxToolkit:ToolkitScriptManager>
Remarks: here you can find example of the config which contains most (maybe all definition of the controls from ajax control toolkit library).
这篇关于Ajax Control Toolkit 正在加载过多的脚本资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!