views:

262

answers:

2

If you have too many javascript file includes with a compositescript in a script manager you get this error...

"The resource URL cannot be longer than 1024 characters. If using a CompositeScriptReference, reduce the number of ScriptReferences it contains, or combine them into a single static file and set the Path property to the location of it."

I know how to fix this using a plane old asp:scriptmanager (use script manager proxies). But how do I fix it using a ToolkitScriptManager?

<ajaxToolkit:ToolkitScriptManager ID="GeneralScriptManager" CombineScripts="true" CombineScriptsHandlerUrl="Utility/CombineScriptsHandler.ashx" runat="server" AsyncPostBackTimeout="480" EnablePageMethods="true">
    <CompositeScript>
        <Scripts>
            <asp:ScriptReference Path="JavaScript/jQuery/jquery-1.4.1.min.js" />
            ... A whole lot more script references here
        </Scripts>
    </CompositeScript>
</ajaxToolkit:ToolkitScriptManager>

Update I've tried doing this with the script combiner included in the sample application. I think it's right, but I've been wrong plenty of times before... No luck though.

Another update So, I thought that maybe if I included multiple CompositeScript blocks within the single ToolkitScriptManager it might create them all as separate files. Nope. Still get the same error. No one has any ideas? When I Google "toolkitscriptmanager cannot be longer than 1024 characters" this StackOverflow question is the number 1 result...

+2  A: 

The MSDN documentation on this is actually pretty good:

The number of script references that a CompositeScriptReference instance can contain is limited by the size of the resulting URL. The URL cannot be longer than 1024 characters.

If you have to work around this limitation, you have two options. The first option is to reduce the number of ScriptReference objects that the composite script contains. The second option is to manually combine the scripts into a single static file. In that case, you can set the Path property to the location of the static file.

If you're looking to combine multiple physical files, you're going about it the wrong way - see the link below [1]:

You can combine multiple physical script files using that feature, but we really don't recommend it as there is some server overhead related to file monitoring. What you're describing is much better handled by "building" your scripts at compile time instead of doing the combination at runtime. The feature really is for application developers who want to combine existing scripts from various components that they use in their application.

What I would look for is a post-build task that combines your static *.js files, something like [2].

Good luck.

[1] - http://weblogs.asp.net/bleroy/archive/2008/06/12/script-reference-profiler.aspx

[2] - http://encosia.com/2009/05/20/automatically-minify-and-combine-javascript-in-visual-studio/

Nariman
Thanks for the answer. However, I'm a bit confused with regards to your second point. What is the purpose of using a CompositeScript then?
Carter
To combine embedded scripts - e.g: <asp:ScriptReference Name=”MicrosoftAjax.js” /> <asp:ScriptReference Name=”MicrosoftAjaxWebForms.js” /> <asp:ScriptReference Name=”MyEmbeddedScript.js” Assembly=”MyAssembly” />
Nariman
Thanks for the insights, although I was able to dig up most of this before I posted the question, it's becoming apparent it's the only real answer.
Carter
A: 

I use Chirpy instead of the ToolkitScriptManager. It's easy to configure, does js and css files. It can use YUI-Compressor or Google Cloture under the covers.

Also allows you to use lesscss which is awesome.

Matt Dotson