How to: Merge and Compress Custom CSS and JavaScript Files
- 2 minutes to read
ASPxHttpHandlerModule allows you to merge and compress custom CSS and JavaScript files, which can significantly improve application performance.
To enable this functionality, register ASPxHttpHandlerModule in the web.config file’s system.web/httpHandlers and system.webServer/handlers (for IIS7 in integrated mode) sections.
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.
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 (within code) 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
To allow ASPxHttpHandlerModule to compress files, set the Resource Compression attribute to true
(the default value).
If an error occurs during merge or compression, the server returns an internal server error (500) – which displays a description of the error in an HTTP status message.