The Dopefly Tech Blog

« The Dopefly Tech Blog Main page

Forget cfsilent, this is better!

posted under category: ColdFusion on August 19, 2004 by Nathan

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.

Nathan is a software developer at The Boeing Company in Charleston, SC. He is essentially a big programming nerd. Really, you could say that makes him a nerd among nerds. Aside from making software for the web, he plays with tech toys and likes to think about programming's big picture while speaking at conferences and generally impressing people with massive nerdiness and straight-faced sarcastic humor. Nathan got his programming start writing batch files in DOS. It should go without saying, but these thought and opinions have nothing to do with Boeing in any way.
This blog is also available as an RSS 2.0 feed. Click your heels together and click here to contact Nathan.