The Dopefly Tech Blog

<< The Dopefly Tech Blog Main page

Forget cfsilent, this is better!

posted under category: ColdFusion on August 19, 2004 at 2:00 am by MrNate

Two thigs I hate:

1. White space at the top of my HTML doc, before anything loads, causing larger download sizes.
2. White space at the top of my XML docs, invalidating the XML (to some XML engines).

What can you do to avoid this in ColdFusion? Historically, ColdFusion 4 had <cfsetting enablecfoutputonly="yes">. While this works, it requires you to put <cfoutput> around everything you do want to output to the browser.

Newer still, ColdFusion 5 introduced the <cfsilent> tag. Absolutely nothing inside the cfsilent tagsets is outputted. This is nice, but for my purposes, it requires me to wrap it around the top of every page... "Now where was that cfsilent starting block?"

Now, thanks to CFMX and the underlying J2EE engine, we can use the amazingly powerful getPageContext(). Here is what I have been putting at the top of my pages and XML docs lately:

<cfset getPageContext().getOut().clearBuffer()>
This successfully clears the output buffer, making it fresh and ready to start anew.

Too old to comment!
On Aug 20, 2004 at 2:00 AM RAFF (admin has underestimated gamescrubs.com) said:
I used this so called getPageContext and all it did was break my code.

Thx man i appreciate the extra work. =P

On Aug 21, 2004 at 2:00 AM MrNate (http://www.dopefly.com/) said:
Completely different problem Raff. You were trying to do a getPageContext().forward() to a page with an error, which throws a JRun error instead of showing you the CF error.
Too old to comment!