CssCompactFormat(sInput)
Last updated November 19, 2002
Version: 1 | Requires: ColdFusion 5 | Library: StrLib
Description:
This function is useful to reduce download time on large CSS style sheets, all unnecessary spaces are removed, pages will load faster. And your lovely CSS wont be ripped off as easily.
Return Values:
Returns a string.
Example:
<cfsavecontent variable="css">
.TextBig {
font-size : 12pt;
font-weight : normal;
font-family : arial;
}
.TextSmall {
font-size : 9pt;
font-weight : normal;
font-family : arial;
}
.TextTiny, SMALL {
font-weight : normal;
font-size : 8pt;
font-family : helvetica;
}
</cfsavecontent>
<b>Before:</b><br>
<style type="text/css">
#HtmlCodeFormat(css)#
</style>
<p>
<b>After:</b><br>
<style type="text/css">
#cssCompactFormat(css)#
</style>
</cfoutput>
Parameters:
| Name | Description | Required |
|---|---|---|
| sInput | CSS you want to compress. | Yes |
Full UDF Source:
<cfscript>
/**
* Replaces all unnecessary characters from a section of CSS code.
*
* @param sInput CSS you want to compress. (Required)
* @return Returns a string.
* @author Jordan Clark (JordanClark@Telus.net)
* @version 1, November 19, 2002
*/
function CssCompactFormat(sInput) {
sInput = reReplace( sInput, "[[:space:]]{2,}", " ", "all" );
sInput = reReplace( sInput, "/\*[^\*]+\*/", " ", "all" );
sInput = reReplace( sInput, "[ ]*([:{};,])[ ]*", "\1", "all" );
return sInput;
}
</cfscript>
Search CFLib.org
Latest Additions
Tayo Akinmade added
arrayTrim
11 day(s) ago
Will Belden added
longTime
17 day(s) ago
James Sleeman added
quickSort
27 day(s) ago
Ben Forta added
GetHostAddress
30 day(s) ago
Top Rated
EksporSQLData
Rated 5.0, 16 time(s)
backupDatabase
Rated 5.0, 13 time(s)
indentXml
Rated 5.0, 10 time(s)
generateSsccAsn
Rated 5.0, 4 time(s)