I was putting on the finishing touches on a component I’m building for a customer which is using needs to be MS Ajax aware. Part of this was the post I made last week regarding dynamically figuring out whether to send ClientScript script and page insertions to the ScriptManager or the ClientScript manager dynamically. The primary reason for this is to ensure controls work properly when running inside UpdatePanels with MS Ajax. It all works fine.
One nice side benefit of using the ScriptManager to register WebResource urls is that you get automatic Resource Compression. Resource compression is rather useful and something that should be built into ASP.NET in the first place (actually it looks like this will be built in IIS 7 as the dynamic compression module, but I haven’t looked at this closer because it’s of limited use at the moment).
Anyway it looks like System.Web.Extensions has everything it needs to do the resource compression and I was hoping that when you call the Scriptmanager and its RegisterClientScriptResource it would automatically compress with code like this:
ScriptManager.RegisterClientScriptResource(this, this.GetType(), ControlResources.SCRIPTLIBRARY_SCRIPT_RESOURCE);
MS Ajax will automatically generate a call to ScriptResource.axd instead of WebResource.axd. ScriptResources are automatically compressed with GZIP.
This works fine as long a ScriptManager is on the page.
But even though ScriptManager.RegisterClientScriptResource is static, it only calls out to ScriptResource.axd when a ScriptManager is actually on the page so unless you explicitly put a ScriptManager on the page no resource compression takes place which is a bummer.
It also looks like Microsoft pulled out the WebResourceCompression module of the assembly so there’s no more generic compression mechanism which I thought was rather useful. Bummer...
Other Posts you might also like