Skip to content

Where can I use cfflush in my Mach II application?

thofrey edited this page Apr 1, 2014 · 4 revisions

Table of Contents

  1. Typical Situation
  2. The problem with <cfflush> in CFML frameworks
  3. Possible solutions in lieu using <cfflush>

Typical Situation

A question Mach-II users sometimes ask is whether or not it is possible to perform a <cfflush /> inside a view. When attempted, the following error will likely be encountered:

    You have called cfflush in an invalid location, such as inside a cfquery or
    cfthread or between a CFML custom tag start and end tag.

The problem with <cfflush> in CFML frameworks

<cfflush> is a tag used to push data from the server to the client at any point during a request. On it's first use in a request, <cfflush> also pushes the html header information out to the client and anything that is currently in the output buffer (e.g. HTML, XML, etc.).

Because some data leaves the CFML server in a partial form, using <cfflush> has some limitations. Many CFML tags rely on modifying the html header in order to function properly. If the html header has already been sent to back to the client via <cfflush>, these tags cannot do their jobs.

A few examples of CFML tags which rely on their ability to alter the HTML head area are <cfheader />, <cfhtmlheader />, <cflocation />, <cfform> and others.

Furthermore, other tags will error out if a <cfflush /> is placed within their body as they will not be able to finish executing appropriately. One example of a tag which cannot have <cfflush> in its body is the <cfsavecontent /> tag. Under the hood, Mach-II uses <cfsavecontent /> to save the content from a view file and make it available as an argument within the event object. This occurs behind the scenes when Mach-II developers use the "contentArg" attribute in a <view-page> command within their XML configuration file.

The bottom line is that, unfortunately, <cfflush> doesn't "mix well" in certain situations.

Possible solutions in lieu using <cfflush>

Usually, <cfflush /> is used to improve end performance of a page when delivered to a client such as a browser by "flushing" chunks of the end output buffer as the page is processing. However, there are numerous places in which performance of the application can be improved:

  • Remove repeated calls the same or similar logic during the same request (e.g. running the same query many times in the same request)
  • Improving slowly running queries due to poor SQL
  • Query caching
  • Full page caching, partial page caching or widget caching
  • Webserver settings such as enabling gzip or far future expire headers
  • Valid HTML markup
  • Reduction in excessive use of AJAX calls
  • Reduction in file size of resources such images, javascript or flash files
  • Improve slowly performing sections of CFML logic
  • Improve network architecture or connections such as poorly performing database connections or saturated outgoing bandwidth
  • CFML engine tuning

Back to FAQs

Clone this wiki locally