LA.NET [EN]

Jun 12

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 :,,)]

13 comments so far

  1. Delay
    9:17 pm - 6-12-2007

    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. 🙂
    * http://blogs.msdn.com/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx.

    I”ve just created a work item for the WebResourceAttribute issue you mention – thanks for pointing that out.
    * http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=11023

    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.

    Thanks!

  2. Bertrand Le Roy
    9:47 pm - 6-12-2007

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

  3. luisabreu
    9:52 pm - 6-12-2007

    howdy.

    thanks.

    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. luisabreu
    9:55 pm - 6-12-2007

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

  5. Delay
    10:11 pm - 6-12-2007

    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!)
    http://www.codeplex.com/AtlasControlToolkit/WorkItem/View.aspx?WorkItemId=11025

  6. luisabreu
    10:46 pm - 6-12-2007

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

  7. Delay
    10:26 pm - 6-20-2007

    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:
    http://blogs.msdn.com/delay/archive/2007/06/20/script-combining-made-better-overview-of-improvements-to-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx

  8. luisabreu
    8:28 am - 6-21-2007

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

  9. Trent
    9:40 pm - 2-6-2008

    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. Stephen
    10:27 am - 11-5-2008

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

  11. davetiye
    7:16 am - 11-2-2009

    güzel davetiye sözleri ve davetiye metinleri