Forget cfsilent, this is better!
posted under category: ColdFusion on August 19, 2004 at 1:00 am 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:
This successfully clears the output buffer, making it fresh and ready to start anew.