ScriptManager and Resource Compression
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.
Other Posts you might also like
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Resolving Paths To Server Relative Paths in .NET Code
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Back to Basics: Rewriting a URL in ASP.NET Core
- Getting the Client IP Address in ASP.NET Core
The Voices of Reason
# re: ScriptManager and Resource Compression
You know while you're mucking with ClientScript and Resource inclusion - how about trying to get the size of those resource Urls down to a more reasonable size <s>... It's OK for scripts, but for image links these huge URLs add up quickly especially if they're in some sort of list display...
# re: ScriptManager and Resource Compression
I agree that it would be nice to have shorter urls, but we have to code the assembly and resource name info into that. One thing we're trying to do is to always provide a way to reference static files instead, which enables the page developer to mitigate the problem at the cost of managing those files in the site.
# re: ScriptManager and Resource Compression
My script resources are not compressed by ScriptManager.RegisterClientScriptResource even when I have a ScriptManager on the page. I'm using the beta 2. Maybe I'm missing something?
# re: ScriptManager and Resource Compression
# re: ScriptManager and Resource Compression
# re: ScriptManager and Resource Compression
In 3.5 SP1 there are also script combining features available on script manager that might help.
# re: ScriptManager and Resource Compression