Skip to main content
A newer version of this page is available. .

How to: Merge and Compress Custom CSS and JavaScript Files

  • 2 minutes to read

The ASPxHttpHandlerModule provides the ability to merge and compress custom CSS and JavaScript files, which can significantly improve application performance.

To enable this functionality, ASPxHttpHandlerModule should be registered in the system.web/httpHandlers and system.webServer/handlers (for IIS7 in integrated mode) sections within the web.config file.

To merge and compress custom files, specify a folder with resource files, or individual CSS (or JavaScript) files, as a parameter for the ASPxHttpHandlerModule attribute in the <link> tag for CSS files (or <script> tag for JavaScript files) within an aspx file.

The ASPxHttpHandlerModule supports the following attributes.

  • cssfile - compresses the specified CSS file before sending it to the client.

    
    <link href="DX.ashx?cssfile=~/style1.css" rel="Stylesheet" />
    
  • cssfolder - merges and compresses CSS files in the specified folder before sending them to the client.

    
    <link href="DX.ashx?cssfolder=~/Styles" rel="Stylesheet" />
    
  • jsfile - compresses the specified js-file before sending it to the client.

    
    <script src="DX.ashx?jsfile=~/script1.js" type="text/javascript"></script>
    
  • jsfolder - merges and compresses js-files in the specified folder before sending them to the client.

    
    <script src="DX.ashx?jsfolder=~/Scripts" type="text/javascript"></script>
    
  • jsfileset - merges and compresses the specified js-files in order of specification before sending them to the client. Files are separated by a semicolon (;).

    
    <script src="DX.ashx?jsfileset=~/script4.js;~/script5.js" type="text/javascript"></script>
    

Note

Set the Resource Compression attribute to true (default value) to allow the ASPxHttpHandlerModule to compress files.

If an error occurs during merging or compressing, the server returns an internal server error (500) – which displays a description of the error in an HTTP status message.

See Also