CFLib.org – Common Function Library Project

CssCompactFormat(sInput)

Last updated November 19, 2002
Download UDF

author

Jordan Clark                                      Jordan Clark

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:

<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:

<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

Shawn Porter Shawn Porter added
DeMoronize
3 hour(s) ago

Chris Carey Chris Carey added
readPropertiesFi...
1 day(s) ago

Randy Johnson Randy Johnson added
lastDayofWeek
3 day(s) ago

Frank Marion Frank Marion added
sitemapPing
7 day(s) ago

Top Rated

James Sleeman                                     QuickSort
Rated 5.0, 3 time(s)

Barney Boisvert indentXml
Rated 5.0, 3 time(s)

Nathan Dintenfass                                 queryColumnsToSt...
Rated 5.0, 3 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 3 time(s)

Created by Raymond Camden / Design by Justin Johnson