3

I have replaced my asp:ScriptManager control with ajaxToolkit:ToolkitScriptManager with attribute CombineScripts="true".

Now when I view source of HTML page, there is new script tag:

<script src="/MyPage.aspx?_TSM_HiddenField_=ctl00__pageBody_asScript_tscAjaxScripts_HiddenField&amp;_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d3.0.20820.30277%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3a06e896ab-1f8c-4bcb-9cc4-0200671cba8a%3ae2e86ef9%3a1df13a87%3ac4c00916%3aaf22e781%3a9ea3f0e2%3ac7c04611%3acd120801%3a3858419b%3a96741c43%3a38ec41c0" />

But also are still old script tags: WebResource.axd and several ScriptResource.axd

How do I remove WebResource.axd and ScriptResource.axd links from the page?

Brad
  • 15,361
  • 6
  • 36
  • 57
ihorko
  • 6,855
  • 25
  • 77
  • 116
  • Did you follow the advice in here? http://stackoverflow.com/questions/626659/combine-scripts-in-asp-net-ajax-toolkit – Shadow The GPT Wizard Nov 30 '10 at 14:31
  • I just read it but there is no answer how do I remove WebResource.axd and ScriptResource.axd links – ihorko Nov 30 '10 at 14:51
  • @ihorko try not calling RegisterClientScriptResource in your code. – Shadow The GPT Wizard Nov 30 '10 at 14:55
  • hm, just search in all my files, and didn't find RegisterClientScriptResource in my code. Thanks – ihorko Nov 30 '10 at 15:25
  • Huh, stupid solution from Microsoft as always. So when CombineScripts attribute set to false, my page has 14 ScriptResource.axd files but if it sets to "true" then I have 5 links (1 - WebResource, 3 - ScriptResource, 1 - script src="/MyPage.aspx?_TSM_HiddenField...) ! But I need only one link (combine all scripts to one). What is advantage to use ToolkitScriptManager ???????? – ihorko Nov 30 '10 at 15:50
  • Check what each of those five JS files contain.. is this your code at all? I doubt you can combine code of things like AJAX framework.. – Shadow The GPT Wizard Nov 30 '10 at 21:27
  • Did you end up using my solution? – Tomas Jansson Jan 14 '11 at 17:36

4 Answers4

1

In this scenario by setting CombineScripts="true" of ajaxToolkit:ToolkitScriptManager means this will combine all the script files used by the ajax controls on that page, and it will load the combined script in the below form-

<script src="/MyPage.aspx?_TSM_HiddenField_=ctl00__pageBody_asScript_tscAjaxScripts_HiddenField&amp;_TSM_CombinedScripts_=%3b%3bAjaxControlToolkit%2c+Version%3d3.0.20820.30277%2c+Culture%3dneutral%2c+PublicKeyToken%3d28f01b0e84b6d53e%3aen-US%3a06e896ab-1f8c-4bcb-9cc4-0200671cba8a%3ae2e86ef9%3a1df13a87%3ac4c00916%3aaf22e781%3a9ea3f0e2%3ac7c04611%3acd120801%3a3858419b%3a96741c43%3a38ec41c0" />

But in ScriptResource.axd files it will load the Microsoft Ajax library files like - MicrosoftAjax.debug.js and MicrosoftAjaxWebForms.debug.js in separate request. You can make a single request for Microsoft Ajax by combing them.

You can use <CompositeScript> tag explicitly and specify MicrosoftAjax.js,Webform.jsandMicrosoftAjaxWebForms.debug.js to combine them in a single request. In this way you will see only two request for JS, one for combined script of Ajax controls on that page and another for combined script MicrosoftAjax js

nitendra jain
  • 433
  • 4
  • 8
  • 16
1

There are some components of the AjaxControlToolkit that do not support combining scripts. From: http://blogs.msdn.com/b/delay/archive/2007/06/11/script-combining-made-easy-overview-of-the-ajax-control-toolkit-s-toolkitscriptmanager.aspx

The Slider's SliderBehavior.js script uses a fairly obscure feature enabled by the PerformSubstitution property of the WebResource attribute that allows <%= WebResource/ScriptResource %> tags to be embedded in JS files and get resolved before the script is sent to the browser. This behavior isn't currently supported by ToolkitScriptManager

There's no magical flag you can turn on to completely get rid of these file. The advantage of using the ToolKitScriptManager is that it will reduce the number of resources your page requires, leading to better performance. The Webresource.axd and Scriptresouce.axd files are used by the entire application, and not just the AjaxControlToolkit. My advice would be to use a program like Fiddler to see what resources the Scriptresource.axd and Webresource.axd are actually pulling in and work from there.

Joshua
  • 233
  • 3
  • 9
0

If you are using .NET 4.0, you could use the enablecdn attribute on the scriptmanager, and it serves the required JavaScript code from the Microsoft's CDN.

If not, you can still merge them as Scott Hanselman describes here. You can also go one step further and use an HTTP Module/Filter to combine those scripts (WebResource.axd, ScriptResource.axd) into 2 or 3 ones, however, it needs an extensive knowledge of ASP.NET foundation; Or else, you could break the Microsoft Ajax method calls in the app (it's because of those fancy mechanism UpdatePanel uses to update a portion of the page, etc...)

J. Rattz
  • 76
  • 5
0

I wrote a simple handler for this that seems to work fine, but it is for ASP.NET MVC, but it shouldn't be that hard to make it work for webforms too. I put it on github: https://github.com/mastoj/SimpleCompression.

The good parts with my solution are:

  • You don't need two copies of your script; that is, a minified version with the original.
  • You can change compress engine if you want.
  • The files are compressed on the fly and put in the cache on the webb server and client (you can update a version setting to force client to download script again).
  • The files are combined on the fly.
  • The combined and compressed file has file dependency to the original files so they are re-compressed and combined if you for some reason need to test something in prod (but don't do it :)).
  • And it is easy to use, for MVC at least.
Tomas Jansson
  • 22,767
  • 13
  • 83
  • 137