CURRENT PROJECTS
loading
CATEGORIES AND POSTS
loading
overset
DEVELOPMENT LOG FOR JIM PALMER
Posted 09/18/2006 in coldfusion


We all know it doesn't matter what version of ColdFusion your running or what file-type you're developers are saving their CFML in... you will still always have an issue with whitespace being added to your HTML that is sent to every client's browser.

The best solution I've found thus far to combat this issue was found thanks to Dmitry Namiot's posting on the ability to parse the "output buffer" sent to the client. This involves usage of internal ColdFusion Java functionality but is so horribly simple to use. For those PHP buffs, it's exactly like using the "output buffer" ob_* ("ob_start", "ob_get_contents", etc.) functionality which allows futher parsing of the buffer that's sent to the client.

My version piggybacks the Application.CFC's functionality to make sure it happens for EVERY page request that this Application.CFC applies to. Here's the content's of my onRequestEnd function:
<cffunction name="onRequestEnd" output="Yes"><cfsetting enablecfoutputonly="Yes">
	<!--- forceful strip of whitespaces from CFMX Java output buffer - idea thanks to Dmitry Namiot --->
	<cfset pageContent = getPageContext().getOut().getString()>
	<cfset getPageContext().getOut().clearBuffer()>
	<cfset pageContent = REReplace(pageContent, "^[[:space:]]+<", "<", "all" )>
	<cfset pageContent = REReplace(pageContent, ">[[:space:]]+$", ">", "all" )>
	<!--- capture pure whitespace pages for those CFLOCATION tags in the middle of a logic block --->
	<cfset pageContent = REReplace(pageContent, "^[[:space:]]+$", "", "all" )>
	<cfset writeOutput(pageContent)>
	<cfset getPageContext().getOut().flush()>
<cfsetting enablecfoutputonly="No"></cffunction>
comments
loading
new comment
NAME
EMAIL ME ON UPDATES
EMAIL (hidden)
URL
MESSAGE TAGS ALLOWED: <code> <a> <pre class="code [tab4|tabX|inline|bash]"> <br>
PREVIEW COMMENT
TURING TEST
gravatar