CFLib.org – Common Function Library Project

CssCompactFormat(sInput)

Last updated November 19, 2002

author

Jordan Clark

Version: 1 | Requires: CF5 | 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:

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

/**
 * 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson