Should I treat direct CFC Calls differently than Page Requests? Should I leave in &lt;cfif reFindNoCase( "\.cfc$" , targetPage ) eq 0&gt; or not?

Direct CFC calls are flushed when the method returns. Either way, onRequestEnd will stop debug output from being returned for AJAX requests.

Keep If Statement

Additional regular expression search on every AJAX call. Direct CFC calls return quicker. Direct CFC call may not be trimmed.

Remove If Statement (inner code executes for all AJAX requests)

Direct CFC calls' value is stored in a variable. AJAX calls to pages return quicker. All AJAX responses are trimmed.

I'm using ColdFusion 8.

&lt;cfcomponent output=    "false"&gt;

&lt;cfset this.name=   "AJAX Debug Output" /&gt;

&lt;cffunction name=   "onRequestEnd"
        returnType= "void"
        hint=       "I run on the end of requests (how clever)."&gt;

    &lt;cfargument name=   "targetPage"
                hint=   "Path from the web root to the requested page." /&gt;

    &lt;cfif isAJAXRequest()&gt;
        &lt;cfsetting  showDebugOutput=    "false" 
                    enableCFOutputOnly= "true" /&gt;

        &lt;!--- Response from CFC is already flushed to browser. Skip output. ---&gt;
        &lt;cfif reFindNoCase( "\.cfc$" , targetPage ) eq 0&gt;

            &lt;!--- If AJAXResponse is not set, then generated content is response. ---&gt;
            &lt;cfparam    name=       "request.AJAXResponse"
                        default=    "#getPageContext().getOut().getString()#" /&gt;

            &lt;cfcontent  reset= "true" /&gt;
            &lt;cfoutput&gt;#trim( request.AJAXResponse )#&lt;/cfoutput&gt;
            &lt;cfabort /&gt;

        &lt;/cfif&gt;

    &lt;/cfif&gt;

&lt;/cffunction&gt;

&lt;cffunction name=   "isAJAXRequest" 
            output= "false"
            access= "private"
            hint=   "I check to see if the request came across with ajax headers"&gt;

    &lt;cfif structKeyExists( getHTTPRequestData().headers , "X-Requested-With" )&gt;
        &lt;cfreturn true /&gt;

    &lt;/cfif&gt;

    &lt;cfreturn false /&gt;

&lt;/cffunction&gt;

&lt;/cfcomponent&gt;
If you're using ColdFusion 9, you can use onCFCRequest to deal with this type of issue. Which version of CF are you using?