Telerik Telerik
The Telerik Blogs

HTTP Compression for your ASP.NET AJAX applications

Tuesday, December 16, 2008 by Vladimir Enchev | Comments 21

With our next service pack you will be able to compress your entire AJAX traffic completely codeless with a single web.config setting:

...
<httpModules> 
  <add name="RadCompression" type="Telerik.Web.UI.RadCompression" /> 
</httpModules> 
...
  <!--
        The system.webServer section is required for running ASP.NET AJAX under Internet
        Information Services 7.0.  It is not necessary for previous version of IIS.
    --> 
  <system.webServer> 
    <modules> 
       <add name="RadCompression" type="Telerik.Web.UI.RadCompression" /> 
    </modules> 
...

Features:
Support for all traditional ajax requests including RadAjaxManager, RadAjaxPanel, plain UpdatePanel, etc.
Support for all WebService requests with content type "application/json"
Support for all modern browsers including IE7, FireFox, Chrome, etc. IE6 is not supported however you will not get any errors - just uncompressed response!

Limitations:
Will not support Microsoft ASP.NET AJAX 1.0 (available only for .NET 3.5)
Will not support PageMethods

The module will work also without any problems with IIS7 compression!

To check what is the real benefit I've made small demo with two grids:

- first grid bound to LinqDataSource and ajaxified using RadAjaxManager (traditional ajax)

- second grid bound to a WebService (client-binding) with pure JSON response

The result? Page to page two Northwind Customers table with ten records per page:

- traditional ajax: Bytes Received: 3,436 (uncompressed 7,842)
- JSON: Bytes Received: 1,523 (uncompressed 2,965)

Enjoy!

[Live | Download]

21 Comments

  • Chameleoki 16 Dec
    If we have gzip compression enabled through IIS, will we still want to do this option in addition?
  • Vlad 17 Dec
    Hi Chameleoki, Here is the result with default IIS7 compression (without our compression module): - traditional ajax: Bytes Received: 3,883 - JSON: Bytes Received: 2,910 - NO COMPRESSION! Vlad PS: Both "Enable Dynamic Content Compression" and "Enable Static Content Compression" are turned on!
  • Mark R. 17 Dec
    We're using ASP.NET 2.0 / AJAX 1.0, and I'm curious as to why this won't be supported.
  • Tom 17 Dec
    What's the scheduled release date for the next service pack?
  • max 18 Dec
    What about the view state? it becomes huge very fast..
    There is a lot of samples on google and it would be nice if you include event this feature..
  • Vlad 18 Dec
    Hi Mark, So far we succeeded with web services JSON compression under .NET 2.0 and Microsoft ASP.NET AJAX 1.0 only - I'll post more info for ajax response (if we have any). Hi Tom, The service pack is scheduled for the first week of 2009 however you can contact the support to receive latest unofficial Telerik.Web.UI build. Hi Max, So far we don't have plans related to ViewState handling - you can use the standard approach (for example SessionPageStatePersister similar to my demo).
  • Cedric 18 Dec
    I'm wondering why it doesn't work with pagemethods...
  • Vlad 19 Dec
    Hi Cedric, Good news - we've managed to add support for PageMethods as well. Vlad
  • Vlad 20 Dec
    Hi all,
    I'm happy to announce that Telerik.Web.UI.CompressionModule will support ASP.NET 2.0 and Microsoft ASP.NET AJAX 1.0.
    Vlad
  • Carlos 03 Jan
    We are looking for  HTTP Compression  and we find http://www.codeplex.com/MbCompression with

    Features:
    1. Minify and compress JavaScript files.
    2. Minify and compress css files.
    3. Compress aspx pages.
    4. Minify and compress WebResource.axd
    5. Combine multiply javascript or css files to save requests

    Advantages:
    1. Easy to implement in existing project.
    2. Every feature can be enabled or disables by configuration in Web.Config file.
    3. All external files (js, css) and WebResources are been cached in client & server.
    4. Time in the cache can be controlled in the Web.Config
    5. Specified type of content can be exclude from the compression
    6. Specified aspx files can be exclude from the compression
    7. JavaScript files that 'injected' by third party component (as Telerik controls) can be compressed too.
    8. Frameworks 2.0, 3.0 & 3.5
    9. The System.Web.Handlers.AssemblyResourceLoader that load the WebResources was rewritten to enable compression and better performance, and without
    making HTTP request each time WebResource need to be served.

    is telerik HTTP Compression  is better then MB Compression ? can you give test results for example can telerik module compress axd files and viewstates?
  • Jason 15 Jan
    Of course, MbCompression  is better.....
    Telerik compression module is still weakless
  • Vlad 20 Jan
    Hi Carlos, Straight onto your questions: - Features from 1 to 5 are part of RadScriptManager and RadStyleSheetManager. 1) Simple and standard http module registration - no need to learn custom config tags. 2) You can configure our compression using RadCompressionSettingsAttribute attribute My opinion is that 3) and 4) are mostly browser/server related. 5) Currently not supported. 6) Please check 2) 7) Supported. 8) Same. 9) Please check RadScriptManager. Furthermore you can compress the ViewState using simple .browser file in your App_Browsers folder: <browsers>   <browser refID="Default">     <controlAdapters>       <adapter controlType="System.Web.UI.Page" adapterType="Telerik.Web.UI.RadHiddenFieldPageStateCompression" />     </controlAdapters>   </browser> </browsers> The page state can be compressed using RadHiddenFieldPageStateCompression or RadSessionPageStateCompression. Hi Jason , Can you share what do you mean by "still weakless"?
  • JohnC 23 Jan
    Vlad, this simply doesn't work. I'm using the latest build 2008.3.1314.35 12/11/2008 is there a special build I need or ...?

    Here is the error I get:
    --------------------------------------------------------------------------------

    Configuration Error
    Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

    Parser Error Message: Could not load type 'Telerik.Web.UI.CompressionModule'. (C:\data\MyAPP\source\WBI\web.config line 70)

    Source Error:


    Line 68: <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    Line 69: <add name="RadUploadModule" type="Telerik.Web.UI.RadUploadHttpModule, Telerik.Web.UI" />
    Line 70: <add name="TelerikCompressionModule" type="Telerik.Web.UI.CompressionModule" />
    Line 71: </httpModules>
    Line 72: </system.web>


    Source File: C:\data\MyApp\source\xxx\web.config Line: 70


    --------------------------------------------------------------------------------
    Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433
  • Vlad 26 Jan
    Hi John,
    The name of the class was changed from CompressionModule to RadCompression for the official release.
    Sorry for the confusion!
    Vlad
  • JohnC 26 Jan
    Shouldn't you update the example web.config snippet at the top then? :)
  • Vlad 27 Jan
    Done!
  • XavierT 04 Feb
    Where can I find documentation on

    2) You can configure our compression using RadCompressionSettingsAttribute attribute


    RadHiddenFieldPageStateCompression or RadSessionPageStateCompression

    thanks
  • Chetanya 09 Oct
    Does the radcompression reduce the size of the data returned from WebResource.axd? file requests?

    Thanks
  • Goce 13 Apr
    Where should i put this in web.config

    <radCompression>   
      
    <excludeHandlers>
           
    <!--This will match only the defaultcs.aspx file inside a grid folder in web site’root-->
           
    <add handlerPath="grid/defaultcs.aspx" matchExact="true"/>
           
    <!--This will match every defaultvb.aspx file regardless of its location in the web site-->
           
    <add handlerPath="defaultvb.aspx" matchExact="false"/>  
           
    <!--This will match the handlers of all pages which reside in the MyFolder sub-folder of the web site-->  
           
    <add path="MyFolder/" matchExact="false"/>
      
    </excludeHandlers>
    </
    radCompression>

  • Goce 13 Apr
    Where should i put this in web.config

    <radCompression>   
      
    <excludeHandlers>
           
    <!--This will match only the defaultcs.aspx file inside a grid folder in web site’root-->
           
    <add handlerPath="grid/defaultcs.aspx" matchExact="true"/>
           
    <!--This will match every defaultvb.aspx file regardless of its location in the web site-->
           
    <add handlerPath="defaultvb.aspx" matchExact="false"/>  
           
    <!--This will match the handlers of all pages which reside in the MyFolder sub-folder of the web site-->  
           
    <add path="MyFolder/" matchExact="false"/>
      
    </excludeHandlers>
    </
    radCompression>

  • Jonah 02 Oct
    What about in-browser-compression of data before sent to the server?
    I've found something that sounds interesting...AJAX post compression
    Is there something similar?

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)