CyberHawk
CyberHawk

Reputation: 968

Ajax contol toolkit: how to load only scripts needed now that ToolkitScriptManager is obsolete

We are using Ajax Control toolkit. We installed this:

https://www.nuget.org/packages/AjaxControlToolkit.StaticResources/

We already used ACT for bundling, by setting it in web config:

<asp:ScriptManager ID="sm" runat="server" EnableCdn="true" >
            <Scripts>
                <asp:ScriptReference Path="~/Scripts/AjaxControlToolkit/Bundle" />
            </Scripts>
        </asp:ScriptManager>

We are optimizing the page and we noticed, that script is almost 1MB.

This:

AJAX Control Toolkit Loading All Scripts

and this:

http://stephenwalther.com/archive/2013/07/25/july-2013-release-of-the-ajax-control-toolkit

would solve our problem.

But in new versions of Ajax Control Toolkit ajaxToolkit:ToolkitScriptManager is obsolete, so we can not use ControlBundles in script manager.

My question is: how to load only scripts we need (we are using drop down, rating and slider)?

We are using:

Edit: what I did so far: added AjaxControlToolkit.config to root and inserted this

<?xml version="1.0"?>
<ajaxControlToolkit>
  <controlBundles>
    <controlBundle name="AjaxBundle">
      <control name="CalendarExtender" />
      <control name="ComboBox" />
    </controlBundle>
  </controlBundles>
</ajaxControlToolkit>

Added scriptmanager to masterpage:

<asp:ScriptManager ID="sm" runat="server" EnableCdn="true" >
            <Scripts>
                <asp:ScriptReference Path="~/Scripts/AjaxControlToolkit/AjaxBundleBundle" />
            </Scripts>
        </asp:ScriptManager>

Added this to Global asax to application start:

BundleTable.Bundles.Add(new ScriptBundle("~/Script/js-master".Include("~/Scripts/AjaxControlToolkit/AjaxBundle"));

On masterpage I also have:

<%: System.Web.Optimization.Scripts.Render("~/Script/js-master") %>

I intentionally missed out slider extender (so it shouldn't work), but it is working anyway, so I guess all the Ajax Control Toolkit scripts are loaded.

Web config, also:

<compilation debug="false" targetFramework="4.5.1">

Upvotes: 1

Views: 1670

Answers (2)

Thierry_S
Thierry_S

Reputation: 1616

In addition to the js scripts, the toolkit will load a few CSS files too. To prevent it from loading these WebResource.axd with css and image content, you can use web.config:

<configSections>
    <section name="ajaxControlToolkit" type="AjaxControlToolkit.AjaxControlToolkitConfigSection, AjaxControlToolkit" requirePermission="false"/>
</configSections>

<ajaxControlToolkit renderStyleLinks="false" />

To see the content of the files, in a test project, install the nuget package AjaxControlToolkit.StaticResources which has all images, css and js.

For example, I use the CalendarExtender, but I don't want an extra http request to get the little left and right arrows, so I've customised the css to use my own generic sprite. Same for Combobox down arrow, I actually use the Bootstrap caret character/style instead of an image.

Upvotes: 0

Mikhail Tymchuk
Mikhail Tymchuk

Reputation: 896

Actually, you can. This feature is kept for backward compatibility.

You don't need to specify it explicitly anymore. Toolkit scans for AjaxControlToolkit.config file in application root (specifically, HttpRuntime.AppDomainAppPath) and makes control bundles from it.

Upvotes: 2

Related Questions