CFLib.org – Common Function Library Project

CssCompactFormat(sInput)

Last updated November 19, 2002

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

 
Rated 2 time(s). Average Rating: 4.0

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:

view plain print about
<cfoutput>
<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>
&lt;style type="text/css"&gt;
#HtmlCodeFormat(css)#
&lt;/style&gt;
<p>
<b>After:</b><br>
&lt;style type="text/css"&gt;
#cssCompactFormat(css)#
&lt;/style&gt;

</cfoutput>

Parameters:

Name Description Required
sInput CSS you want to compress. Yes

Full UDF Source:

view plain print about
<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>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
11 day(s) ago

Will Belden Will Belden added
longTime
17 day(s) ago

James Sleeman James Sleeman added
quickSort
27 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
30 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson