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;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson