16.7. Using Compression for Scripts
Modern browsers have the ability to decompress files, so you can reduce the time needed to download files to the browser by sending them in a compressed format. Text files compress very well. For example, the MicrosoftAjax.js file is more than 100K originally, but when compressed, it is reduced to about one third that size. It requires some extra CPU usage on the server to do the compression, but the compressed scripts can be cached on the server, so the processing overhead shouldn't matter much. The client will decompress the file once and then cache it as well, so the impact is minimal and the overall effect can be a benefit to the server and to the client.
16.7.1. Compression of Dynamic Scripts
Scripts embedded as a resource within a dll and extracted by ASP.NET on demand are referred to as dynamic scripts. ASP.NET AJAX supports compressing those scripts as they are extracted from the DLL. Custom controls that use the ScriptManager to access their dynamic scripts also get the benefit of having their JavaScript compressed and cached.
The compression of dynamic scripts is controlled in the web.config file. The enableCompression and enableCaching attributes should be set to true:
system.web.extensions> <scripting> <scriptResourceHandler enableCompression="true" enableCaching="true" /> </scripting> </system.web.extensions>
Note that there are some tradeoffs in using compression and caching. Using compression without caching will make the server ...
Get Professional ASP.NET 3.5 AJAX now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.