CFSilent vs. CFContent Reset = True

Posted October 26, 2006 at 3:26 PM by Ben Nadel

Tags: ColdFusion

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

Oct 26, 2006 at 5:10 PM // reply »
10 Comments

can you show some sample. And also, do u prefer using Application.cfc over Application.cfm?


Oct 26, 2006 at 5:56 PM // reply »
11,238 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.


Oct 26, 2006 at 7:21 PM // reply »
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?


Oct 27, 2006 at 7:16 AM // reply »
11,238 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:

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


Oct 27, 2006 at 7:28 AM // reply »
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.


Nov 28, 2007 at 2:19 PM // reply »
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!"


Nov 28, 2007 at 2:33 PM // reply »
11,238 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.


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
May 17, 2013 at 7:42 PM
HashKeyCopier - An AngularJS Utility Class For Merging Cached And Live Data
Ben - thanks so much for posting these Angular articles and findings, they've been a huge help towards learning one of the more 'complex' JavaScript frameworks out there (IMO). I have been using Angu ... read »
May 16, 2013 at 5:01 PM
UPDATE: Parsing CSV Data Files In ColdFusion With csvToArray()
Your code was the closest thing I've found to obtaining some direction for converting ISO fields to values that CF can translate properly. Thank you for posting! ... read »
May 15, 2013 at 10:37 PM
Very Simple Pusher And ColdFusion Powered Chat
hi id making plz easy ... read »
May 15, 2013 at 6:07 PM
Making SOAP Web Service Requests With ColdFusion And CFHTTP
Ben, you once again saved my bacon at work. Thank you, thank you, thank you! ... read »
May 15, 2013 at 4:15 PM
What If All User Interface (UI) Data Came In Reports?
@Josh, Thanks! @Ben, I definitely recommend the David West book "Object Thinking" I've been quoting from. It goes deeply into the philosophy and history of OO programming. His breadth ... read »
May 15, 2013 at 11:36 AM
Ask Ben: Print Part Of A Web Page With jQuery
I found this helpfull when you need to keep (refresh) the original parent page after closing the iframe child print dialog (Hoping you're not using a form at this time so it won't submit again): On ... read »
May 14, 2013 at 7:13 PM
What If All User Interface (UI) Data Came In Reports?
@Jonah, If there's any books you'd recommend on the subject of domain modelling, I'd love to hear it. I just downloaded the free PDF of "Domain Driven Design Quickly". Figured I'd give it ... read »
May 14, 2013 at 6:57 PM
The UX Of Prototyping: Low-Fidelity Is The New High-Fidelity
@Phillip, I'm not sure I follow what you mean? Are you saying that you looked at the list of widgets provided by the jQuery UI and let that be your style guide? ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools