In my previous post I’ve described how to enable data compression on IIS 6.0 server. The problem I’ve discovered while analyzing HTTP traffic with Fiddler and YSlow is that somehow IIS does not compresses WebResource.axd files. In ASP.NET websites with extensive use of Ajax this issue reduces site’s performance significantly, because of size and amount of axd files in use.
Before enabling data compression on IIS:
After enabling data compression on IIS:
Although data compression was enabled, axd file was not compressed without any obvious reason. To overcome this obstacle within ASP.NET applications HttpModule must be implemented. It will compress an axd files on http response. An implementation’s algorithm is pretty simple:
- Subscribe to BeginRequest and EndRequest events.
- On BeginRequest validate if any data compression can be applied on axd file. If not, bypass all module’s events.
- On EndRequest apply data compression to a axd file. Standard .NET classes can be used to apply GZip or Deflate compression – DeflateStream and GZipStream. If browser supports deflate data compression – prefer it, because of performance reason, here are some explanations.
- Set an expiration data to some reasonable time span – reduces number of server requests.
After applying suggested solution YSlow shows an ideal “A” grade:
By enabling this HttpModule, network utilization for ASP.NET application, using Ajax, reduced significantly because of a fact that axd files sizes are big without compression and there is no caching for those files by default.
If you have any questions about an implementation of HttpModule I’ll be glad to help. Any way I’ve checked two examples that are ready for download :
Hope this post will help to improve your applications…