ToolkitScriptManager: there''s a new ScriptManager in town

Besides fixing some bugs and adding some new features to the existing controls, the new release of the AJAX Toolkit introduces the ToolkitScriptManager control. This new control lets you combine several embedded scripts on a single download, which might improve the performance of your page in some scenarios.

Its usage is simple: you add the ScriptCombineAttribute attribute to the assembly that contains the JS files you want to be combined and add a ToolkitScriptManager control to the page (making sure that the CombineScripts property of the control is set to true – which is the default).

When you apply the attribute to an assembly, all the scripts embedded on the dll that are need for a specific page will be combined in a single download. You can also specify which files should and shouldn”t be combined by setting the ExcludeScripts and IncludeScripts properties (as you can guess by their names, the IncludeScripts property lets you specify which scripts should be combined or excluded from the single download file that is generated by the control).

There are some interesting side effects associated with this new model. The first thing i”ve noticed is that the usage of the WebResourceAttribute is no longer necessary. The only thing i needed to do to download the javascript code was to embed the file on the dll. To me this isn”t a big issue. Others might disagree.

Another difference when you think about loading js files: you no longer need to call the Sys.Application.notifyScriptLoaded method at the end of the js files that are combined into a single download.The control automatically calls that method for you, so there”s nothing to worry about.

To me, the control”s greatest advantage is that  you”ll automatically get a single download which is compressed (using the GZIP or Deflate algorithm) and cached by the browser. The internal implementation of the control is also interesting. The control inserts a script element whose generated url points to the current page and uses a query parameter (named _scriptcombiner_) to specify the list of scripts that should be combined into a single one. During the Init event, the control checks the value of that query string parameter. If it”s not null, it”ll generate a custom response that inserts the requested js files on the page and end the current request.

[Update: Delay has a great post which explains in great depth how this new control works. If you want to know everything about it, go read it now :,,)]


~ by Luis Abreu on June 12, 2007.

11 Responses to “ToolkitScriptManager: there''s a new ScriptManager in town”

  1. Luis,

    Great write-up!

    If you”re interested, please have a look at my blog for a little more detail on how ToolkitScriptManager works – and why. 🙂

    I”ve just created a work item for the WebResourceAttribute issue you mention – thanks for pointing that out.

    Your comment about notifyScriptLoaded is good – though you”ll notice that none of the AJAX Control Toolkit scripts called that method because ScriptResource.axd adds it automatically for any scripts it serves.


  2. Minor remark: if you use the regular script manager, you don”t need to add the notification line either.

  3. howdy.


    yeah, you”re right about extenders and scriptresource. and if i”m not mistaken, you can also add that line automatically when loading a script by using the notifyscriptloaded property of the scriptreference object.

    however, i thought it was best to mention this because there”s always the chance of having a dll with embedded js files and you might be using a scriptelement to add a reference to that js file.

    maybe there should be a recommendation for not adding the notifyScriptLoaded method to the end of the file (making us use the notifyscriptloaded property of the scriptreference element).

    btw, a question: isn”t there a possibility of running out of chars on the query string when you have several js files and several assemblies?

  4. Yes, Bertrand. As always, you”re correct. 🙂

  5. Luis,

    Yes, the length of the combined script URL is something we”d like to decrease. I mention it briefly in my blog, but hadn”t gotten around to opening a work item until earlier today. (Just a bit before you asked, in fact!)

  6. Delay: the query string length was something i forgot to mention in my initial post. compressing it looks good to me 🙂

  7. FYI, as of the 10618 release of the AJAX Control Toolkit, WebResourceAttribute is now required and the combined script URLs are much shorter. Additionally, there”s a new CombinedScriptsHandlerUrl property that”s pretty handy:

  8. Hello.
    yes, I”ve been told that there are improvements, but still wasn”t able to download and test the latest version.

  9. Has anybody noticed the increased PreRenderComplete times when using this control? My best guess is that there is some expensive operation during this method when trying to combine scripts. The implications were significant within our app. Script combination only saved a *fraction* of total download size, where I gained .7 seconds on the server for rendering this script. Definetly a deal breaker.

  10. When applying the script do you add in for all pages or just for the ones that you want to go faster?

  11. güzel davetiye sözleri ve davetiye metinleri

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: