JavaScript Resource Compression with the ScriptCompression Module

The ScriptCompression module compresses JavaScript <script> links loaded from ASP.NET Resources. The script code is stripped of spaces and line breaks (minfied) and GZip encoded if the client supports it. Script compression kicks in when using the ClientScriptProxy.RegisterClientScriptResource() method, ClientScript.LoadControlsScript() or any script placed in ScriptContainer and set to load a resource.

ScriptCompression is active only if the module is installed in web.config. If not installed the Toolkit will use standard ASP.NET mechanisms (Page.ClientScript or ScriptManager if available) to load scripts so this component is purely optional. If not registered code will not fail. However, we recommend you install the module if you use the toolkit to optimize script loading.

Installation

To install the script compression module add the following to Web.config:

For IIS 7:

<configuration>
   <system.webServer>
      <validation validateIntegratedModeConfiguration="false"/>
      <modules>
         <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web"/>
      </modules>
   </system.webServer>
</configuration>

pre IIS7:
<configuration>
      <httpModules>
         <add name="ScriptCompressionModule" type="Westwind.Web.ScriptCompressionModule,Westwind.Web"/>
      </httpModules>
   </system.web>
</configuration>

Once installed the module listens for wwSC.axd?r=ResourceID&t=TypeName Urls which are processed to provide embedded JavaScript resources in compressed form.

Using the ScriptCompressionModule

If the ScriptCompression module is registered in web.configu, anytime you use ClientScriptProxy.RegisterClientScriptResource() the scripts loaded are automatically compressed.

Note that if ScriptCompression is not installed scripts are loaded using either the ScriptManager (if one is loaded on the page) or Page.ClientScript object. As such the ScriptCompression module is optional but recommended.


© West Wind Technologies, 1996-2016 • Updated: 10/26/09
Comment or report problem with topic