Skip to main content
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Christine Dohmen
Ben Nadel at cf.Objective() 2013 (Bloomington, MN) with: Christine Dohmen

CFSilent vs. CFContent Reset = True

By
Published in Comments (7)

Before I learned that ColdFusion could reset the page buffer (either though the CFContent tag or through GetPageContext()) I used the CFSilent tag to cut down all pre-page processing white-space. Then, once I learned about clearing / resetting the page buffer, I started putting that in my header files right before the doctype definition.

Right now, I use both. All my pre-page processing is still in CFSilent tags AND I reset the buffer prior to page output. Just out of curiosity, I did a test to see if one had a performance difference over the other. As a test I did a TON of pre-page processing on a page that had CFSilent and also on a page that only had a CFContent tag reset the page buffer. As it turns out, there was absolutely no speed difference that I could see.

Good to know. Now I don't have to feel bad about using the combo of the two things. Even though I don't need CFSilent if I use the CFContent tag, it makes me feel more organized, like I knew that I needed to suppress output and did it intentionally. The CFContent tag just feels a bit sloppy, like I am worrying about white-space management as an after thought.

Reader Comments

15,902 Comments

I prefer using the Application.cfc because you get a bit more control over when things are called. It just seems more organized.

As far as an example, I can't really show one because there were so many files. I basically did this in the Application.cfm:

<cfset intStartTime = GetTickCount() />

Then in the header I outputted the difference between that time and the current GetTickCount(). In between those two was a large number of includes and what not. I basically ran it a bunch of times to get a general idea of the speed. Then I did a Exnteded Replace to comment out all CFSilent open & close tags. Then ran the page again a bunch of times.

17 Comments

Hi Ben,

Just curious, I've used cfsetting a lot for this so I was wondering on what your thoughts were for:

<cfsetting enableCFoutputOnly = "true">

...
[ColdFusion logic only, no output]
...

<cfoutput><!DOCTYPE html PUBLIC...
...
[HTML output]
...
</cfoutput>

<cfsetting enableCFoutputOnly = "false">

Seems easier than using <cfsilent>. Thoughts?

15,902 Comments

Michael,

I think there is nothing wrong with using the EnableCFOutputOnly. I don't generally use it mostly because it has no sense of start/end. It's a tag that doesn't have a closing tag. I like the fact that CFSilent has a closing tag. It feels like I am giving my code a nice, warm hug.

But really, it's just personal preference.

FYI, I made a custom that that mimics the EnableCFOutputOnly setting, but DOES use an open/close tag mentality. If you were interested is just seeing it:

www.bennadel.com/index.cfm?dax=blog:297.view

15 Comments

The downside to using cfcontent is that it can make it more difficult when you just want to pop out a quick bit of debugging info in the logic section.
Although that's an upside as well - you can turn it on and not worry about if you've accidentily left some debugging code somewhere... well, so long as the code is before the page starts.

Michael - how is that easier than doing this?
<cfsilent>
...
[ColdFusion logic only, no output]
...
</cfsilent>
<cfoutput><!DOCTYPE html PUBLIC...
...
[HTML output]
...
</cfoutput>

Personally, other than a cfsetting at the top of the application (either index.cfm or application.cfm or application.cfc, as appropriate), I only use it in custom tags (to ensure modularity/portability).

I then tend to use cfsilent around logic, particularly if it's on the same page as some output, although more for markers than actual purpose, since the root level cfsetting should prevent the excess whitespace.

15 Comments

Ben, I gotta hand it to you. Your blog is the missing manual for ColdFusion. It seems like every time I Google a Coldfusion tag, your site comes up, and it's usually the missing piece of information I'm looking for. This entry is a great example.

Up until now, I've "hugged" my business logic with the cfsilent tag to suppress whitespace. I actually stumbled on the cfcontent reset trick reading your post on SMS messages. Like you said, it feels weird not using cfsilent. For me, it's almost become a separator, keeping my business logic nestled away at the top of my templates.

I'm glad I stumbled on this when I did. I ran into a situation where I needed to include a template in my logic under certain conditions. Wrapped in a cfsilent tag, an included template won't output anything. I didn't want to use some of the workarounds I'd used in the past, so resetting the buffer in my layout file (before the doc type) works perfectly.

I don't know how you find the time to document your CF trials, but I'd just like to say a big, "thanks!"

15,902 Comments

@Brad,

Thank you so much! What a really nice thing to say :) That really means a lot to me, and as far as finding time to document my experimentation, certainly encouragement like this is a huge driving force. I am glad that I could help in some way.

I still use CFSilent around a lot of my pre-processing, but I don't kill myself over it anymore. As a matter of default, I use the CFContent / Reset magic so as to kill all the white space. CFSilent, for me, is now just a matter of habit.

I believe in love. I believe in compassion. I believe in human rights. I believe that we can afford to give more of these gifts to the world around us because it costs us nothing to be decent and kind and understanding. And, I want you to know that when you land on this site, you are accepted for who you are, no matter how you identify, what truths you live, or whatever kind of goofy shit makes you feel alive! Rock on with your bad self!
Ben Nadel