Question

I compress my own JS using YuiCompressor, but is there any reason why MicrosoftAjax.js not minified? Or is there some setting to say run the compressed version of it (if there is a compressed version). Or do I need to decompile it and minify the script resource myself?

Was it helpful?

Solution

I'm surprised at these misleading answers.

ASP.NET AJAX has always provided both debug and compressed versions of MicrosoftAjax.js. A combination of the web.config's debug setting and ScriptManager's ScriptMode property control which script is referenced.

Additionally, you may use the "retail" setting to force compressed scripts regardless.

OTHER TIPS

All the scripts in System.Web.Extensions are minified -- there are two versions of each, as Dave Ward's excellent answer points out. ScriptManager by default will use the debug version when the web.config is in debug mode. Flip it to release with the retail setting or debug="false", and look at the script then.

Also, scripts served through WebResourceHandler or ScriptResourceHandler are in fact cached. They are cached in the best possible way -- forever, so they don't even need to 301 on future visits. The querystring is as it is, because it contains encrypted data. It is encrypted because it contains information about the script resource, including an assembly name, and also because it prevents cache flooding attacks.

Not looking for rep here, just wanted to give more detail.

See http://www.codeproject.com/KB/aspnet/AspNetOptimizer.aspx, you need the

enableScriptMinification="true"

option and add MicrosoftAjax.js to the list

Which would you rather have:

  1. MicrosoftAjax.js comes compressed, obfuscated already.
  2. MicrosoftAjax.js comes uncompressed and open so you can read and understand it yourself.

EDIT: In my defense, at the time of writing this answer I had no experience with .NET 3.5; I now realize they have made several much-needed improvements in this area.


Evidently, MS does not feel the JavaScript file size is very important (which is insane). Additionally, based on my experience with MS Ajax, they also inject several SCRIPT tags (sometimes more than 10) into the markup. These tags bring in scripts from a WebResource.axd handler. So ten or more requests have to be made just to get the necessary Javascript to run the page! Just to add to the ridiculousness, they tack on a crazy query string onto the handler URL, which probably prevents the script from being cached by the browser.

This insanity was enough reason for me to ditch MS Ajax completely and switch over to jQuery, which is far better library, especially since Visual Studio now has Intellisense for jQuery.

I can only assume that it has been left as-is for ease of understanding, and as you have already hinted, I see know reason why you can't compress it yourself, it is only JavaScript after all - Although MS might like you to believe otherwise, they don't sprinkle it with magical pixie dust to make it any different! :)

[And let's face it; MS have never been afraid of the size of their code, have they?]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top