Skip to main content
Participant
August 26, 2008
Question

cfoutput abuse

  • August 26, 2008
  • 1 reply
  • 322 views

I have a question abt the overuse of cfoutput tags. For example will the code in Sample 1 run faster than that in Sample2. Specifically can someone throw a light on the differences in the class files which will be generated for the below samples.
Thanks a lot.

Sample1:
<cfoutput>
<input type="text" value="#x#">
<input type="text" value="#y#">
<input type="text" value="#z#">
</cfoutput>

Sample2:
<input type="text" value="<cfoutput>#x#</cfoutput>">
<input type="text" value="<cfoutput>#y#</cfoutput>">
<input type="text" value="<cfoutput>#z#</cfoutput>">
    This topic has been closed for replies.

    1 reply

    Inspiring
    August 26, 2008
    Sample 1 will run faster because you are only executing the cfoutput command once. In Sample 2 you are executing it 3 times.
    codismAuthor
    Participant
    August 26, 2008

    but once the sample2 code is compiled, i believe that there shud be no difference in execution speed. does not the bytecode perform the necessary adjustments ??
    Inspiring
    August 26, 2008
    codism wrote:
    > but once the sample2 code is compiled, i believe that there shud be no difference in execution speed. does not the bytecode perform the necessary adjustments ??

    Pretty much, or if there is a difference it is very tiny and would not
    really compensate for hard to read and maintain code.

    The following does not really apply to the example you provided, but
    using <cfoutput>...</cfoutput> block somewhat like your second example
    can be explained as a form of whitespace management.

    If one uses the <cfsetting enableCFoutputOnly="true"> tag, then only
    content inside of <cfoutput>...</cfoutput> blocks will be sent in the
    response. This can be used to control whitespace something like this.

    <cfsetting enableCFoutputOnly="true">
    <!--- A bunch of cf processing --->
    <cfloop this...>
    <cfloop that...>
    <cfquery something ...>

    <!---output the results--->
    <cfouput>What needs to be seen</cfouput>

    <!---More cf processing --->
    <cfset something equals somethingElse>
    <cfif this or that>
    <cfswitch experssion="#justForFun#">

    <!---again output the results--->
    <cfoutput>Only this will be seen</cfoutput>